I'm sure this problem is easily solved but it is driving me slight crazy at the moment.
I have a form that has multiple buttons on it, the buttons (when clicked) add information to a gridview. When a user clicks on one of these buttons I want to disable the other buttons on the form until the method of the button they clicked has finished.
Here is a snippet of the button code within the form:-
thank you very much Steelymar......I had this code in place earlier today but I was missing the 'return' before calling the JS function - doh!
Please could you suggest a way to disable the button clicked aswell? Disabling the button within the JS method means the method is not called.....I am googling for solutions but would appreciate any help.
lvarney
Member
3 Points
15 Posts
Disabling Buttons within C# method
Nov 16, 2010 11:49 AM|LINK
I'm sure this problem is easily solved but it is driving me slight crazy at the moment.
I have a form that has multiple buttons on it, the buttons (when clicked) add information to a gridview. When a user clicks on one of these buttons I want to disable the other buttons on the form until the method of the button they clicked has finished.
Here is a snippet of the button code within the form:-
<asp:Button ID="ButtonStudentNumber" runat="server" Text="Add Student" onclick="ButtonAddStudent_Click"/>
<asp:Button ID="ButtonAddFile" runat="server" Text="Add File" onclick="ButtonAddFile_Click" />
C# code:-
protected void ButtonAddStudent_Click(object sender, EventArgs e)
{
//IN HERE: I have tried to access the other buttons directly:-
ButtonStudentNumber.enabled = false;
ButtonAddFile.enabled = false;
//I've also tried accessing the buttons through sender object:-
Button but = (Button)sender;
but.FindControl("ButtonStudentNumber");
but.Enabled = false;
}
Can anyone advise me on how is best to achieve this?
Any help appreciated!
Thanks,
Laura
disable buttons
Carlos Farin...
Member
26 Points
8 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 12:41 PM|LINK
Hi,
You want to disable the buttons on the browser (client side), not on the server.
So you have to use JavaScript and not server side code.
If you did understand very well my answer, please contact me again.
See you
Steelymar
All-Star
15283 Points
2239 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 12:46 PM|LINK
try:
<script type="text/javascript"> function DisableButtons() { document.getElementById ("<%=Button2.ClientID %>").disabled = true; document.getElementById ("<%=Button3.ClientID %>").disabled = true; return true ; } </script> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return DisableButtons()" /> <asp:Button ID="Button2" runat="server" Text="Button" /> <asp:Button ID="Button3" runat="server" Text="Button" />Stefan Uzunov
MCTS: .NET Framework 3.5 ASP.NET Applications
lvarney
Member
3 Points
15 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 01:11 PM|LINK
thank you very much Steelymar......I had this code in place earlier today but I was missing the 'return' before calling the JS function - doh!
Please could you suggest a way to disable the button clicked aswell? Disabling the button within the JS method means the method is not called.....I am googling for solutions but would appreciate any help.
Thanks
Steelymar
All-Star
15283 Points
2239 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 01:23 PM|LINK
to disable the clicked button use:
<script type="text/javascript"> function DisableButtons() { document.getElementById ("<%=Button2.ClientID %>").disabled = true; document.getElementById ("<%=Button3.ClientID %>").disabled = true; setTimeout ('document.getElementById ("<%=Button1.ClientID %>").disabled = true;',500) return true ; } </script>Stefan Uzunov
MCTS: .NET Framework 3.5 ASP.NET Applications
bruce (sqlwo...
All-Star
36882 Points
5451 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 01:33 PM|LINK
you should use window.setTimeout to disabled all button, and there is no need for the timeout value
function DisableButtons() { window.setTimeout(function() { document.getElementById ("<%=Button2.ClientID %>").disabled = true; document.getElementById ("<%=Button3.ClientID %>").disabled = true; document.getElementById ("<%=Button1.ClientID %>").disabled = true; }); return true ; }
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> function DisableButtons()</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> document.getElementById ("<%=Button2.ClientID %>").disabled = true; </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> document.getElementById ("<%=Button3.ClientID %>").disabled = true; </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> setTimeout ('document.getElementById ("<%=Button1.ClientID %>").disabled = true;',500)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> return true ; </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div>lvarney
Member
3 Points
15 Posts
Re: Disabling Buttons within C# method
Nov 16, 2010 01:33 PM|LINK
Excellent, does exactly what I need. Many many thanks :-)