Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to check whether the linkbutton is clicked or not using if condition i tried by using linkbuttonname.clicked== true but its not working


C#
<pre> protected void gvShowBugs_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        foreach (GridViewRow row in grdTodyTasks.Rows)
        {
            LinkButton lnkNewclicked = row.FindControl("lnkNew") as LinkButton;
            //ScriptManager.GetCurrent(this).RegisterPostBackControl(lnkFull);
            if (lnkNew.clicked==true)
            {

            }
        }
    }


What I have tried:

i tried by using linkbuttonname.clicked== true but its not working
Posted
Updated 25-Dec-17 19:38pm

1 solution

You can use this code -

C#
protected void btnStartTrans_Click(object sender, EventArgs e)
{
    // Loop through all rows in the grid
    foreach (GridViewRow row in grid.Rows)
    {
        // Only look for `lbClose` in data rows, ignore header and footer rows, etc.
        if (row.RowType == DataControlRowType.DataRow)
        {
            // Find the `lbClose` LinkButton control in the row
            LinkButton theLinkButton = (LinkButton)row.FindControl("lbClose");

            // Make sure control is not null
            if(theLinkButton != null)
            {
                // Enable the link button
                theLinkButton.Enabled = true;
            }
        }            
    }
}
 
Share this answer
 
Comments
kav@94 26-Dec-17 1:45am    
i need to call in page index changing event
Nakhia_ind 26-Dec-17 1:49am    
this may currect
kav@94 26-Dec-17 1:53am    
you did not get my point i guess when i keep if(theLinkButton != null)
{
// Enable the link button
theLinkButton.Enabled = true;
} then each time when i click link button it is going into if block but it should go into if block only when i click that link button
Nakhia_ind 26-Dec-17 2:21am    
clearly I am not understanding but something I guess.So the bellow is given

The html code bellow
<asp:TemplateField HeaderText="Enable">
<itemtemplate>
<asp:LinkButton ID="lbtn" runat="server" Text='<% #Bind("Cat") %>' CommandArgument='<% #Bind("Cat") %>' OnClick="btnStartTrans_Click" CommandName="btnenable">




protected void btnStartTrans_Click(object sender, EventArgs e)
{
LinkButton lbtn = (LinkButton)sender;
lbtn.Enabled = false;

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900