Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  121] [ 3]  / answers: 1 / hits: 21809  / 15 Years ago, fri, may 8, 2009, 12:00:00

I have a button control. Once the user clicks on it, the click event should fire and then the button should get disabled. How can I do this? I have the option to use JQuery or JavaScript or both.



Here is my button declaration:



<asp:Button 
ID=Button1
runat=server
Text=Click Me
onclick=Button1_Click
/>


On the button click code behind, I have added a Response.Write(). That should get executed and then the button should be disabled


More From » asp.net

 Answers
47

For whatever reason, the HTML spec dictates that disabled elements should not be included in POST requests. So, if you use JavaScript to disable the HTML element in the client-side onclick event, the input element will be disabled when the browser assembles the POST request, the server won't be properly notified which element raised the postback, and it won't fire server-side click event handlers.



When you set the UseSubmitBehavior property to false, ASP.NET renders an input element of type button instead of the regular input of type submit that the ASP.NET Button control normally generates. This is important because clicking a button element does not trigger the browser's form submit event.



Instead of relying on a browser form submission, ASP.NET will render a client-side call to __doPostBack() within that button element's onclick handler. __doPostBack will raise the postback explicitly, regardless of what POST data comes through in the request.



With the postback being raised independent of the browser submit event, you're freed of the previously mentioned HTML quirk. Then, you can set an OnClientClick of this.disabled = true;, which will render as this.disabled = true; __doPostBack('Button1', '');, and things will work as intended.


[#99571] Monday, May 4, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;