Click here to Skip to main content
15,900,389 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I am struck with one issue,that disabling of LinkButton in Gridview Control. I search in net,I could not find the solution.

The LinkButton in Gridview. For Each row there is linkbutton is displaying in GV.

Look likes :
XML
 <itemtemplate>
<asp:linkbutton id="lnk" runat="server" text="RunTheJob" command="lnk_Click" commandargument="<%# Eval(" val=")%>" xmlns:asp="#unknown" />        </itemtemplate>

In Code:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   { 
     LinkButton lnkMarkAsRerun =  
              (LinkButton)e.Row.FindControl("lnkMarkAsRerun");
     lnkMarkAsRerun.Attributes.Add("onclick", "return confirm('Are you 
               sure you want to update this task?');");

// Here i Need Logic.. When i Click the LinkButton,a confirm pop is display, if user  click "OK" then only LinkButton Need to Enable= False for Particular Row only.
   }
}



Please Help..

Thanks In Advance...
Posted
Updated 24-Aug-10 2:03am
v2

XML
<asp:LinkButton id="link" runat="server" text="RnTheJob" xmlns:asp="#unknown" OnClientClick="return ToggleEnable(this);"
command = "lnk_Click" commandArgument="<%# Eval("val")%>" />


and write a JavaScript function,

JavaScript
function ToggleEnable(src)
{
var result = confirm('Are you sure you want to update this task?');
src.disabled = result;
return result;
}


You can remove the return false statement if you want it to Postback.
 
Share this answer
 
v3
Comments
senguptaamlan 24-Aug-10 6:38am    
as per the question I believe a small change is needed

function ToggleEnable(src)
{
if(confirm('Are you sure you want to update this task?'))
{
src.disabled = 'false';
}
else
{
src.disabled = 'true';
}
}
Johndas 24-Aug-10 6:40am    
Reason for my vote of 5
oh, it working find...what i am finding is gettting...
Venkatesh Mookkan 24-Aug-10 6:50am    
@senguptaamlan: as per the question, the user want to disable the LinkButton on clicking OK.

So,
src.disabled = confirm('Are you sure you want to update this task?');

should be fine. Please read the question again (if required) to clarify yourself.
Johndas 24-Aug-10 7:37am    
Hi Venkatesh, your logic working fine. I need to smalll changes,When click on LinkButton it disable,and run "Job" or "Query" and reflected in database.. But Not Happening now, when i click "Cancel" of pop window.. it updating...
It should update when i click "OK" and Linkbutton should disable..
please suggest your chages..

Venkatesh Mookkan 24-Aug-10 7:58am    
I have improved (updated) the answer. You should be all right now.
Instead of calling inline javascript confirm dialog, call a javascript function, accept the user selection and make linkbutton disable from javascript something like,

lbtn.disabled  =  confirm('Are you sure you want to update this task?');
 
Share this answer
 
I suggest you do

<br />
<br />
<asp:linkbutton id="link" runat="server" text="RnTheJob" xmlns:asp="#unknown"><br />
OnClientClick="return confirm('Are you sure you want go update this task?');"<br />
<br />
command = "lnk_Click" commandArgument="<%# Eval("val")%>" /><br />
<br />
</code></asp:linkbutton>
 
Share this answer
 

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