Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
JavaScript coding question
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01157580
Message ID:
01157712
Views:
16
I’m sure you found plenty of info but here’s my take. There are many was to accomplish this but you really need to be sure the server code handles a double post since any client solution would not be fool proof.

I like to hide the button and display a message indicating the form has been submitted. As long as your client script does not return false the form will post back to the server and run the button’s click event on the server.

An example of simply hiding the control is to place code in the OnClientClick property:
this.style.visibility='hidden'; return true;
or
this.style.display='none'; return true;

Note that display='none' removes the control and frees the space the control occupied so any objects below the control would shift up.

If you wish to disable the button instead of hiding it then it takes a little more client script code. This is because once you disable the control it will not submit the form. You must therefore manually post the form from your script.

Assuming your button control’s id is “Button1”.
this.disabled=true; __doPostBack('Button1','');

All of these solutions require modern browsers to function correctly. If you have to support older browsers such as Netscape 4.0 you will need to write a function that will deal with the cross browser issues.


>Well, it's my turn to ask a question - i'm really stuck on something.
>
>I have a button on a web form, using ASP.NET 2.0. The button is a save button, where I have a C# method call in the code-behind.
>
>I need to disable the save button IMMEDIATELY when the user clicks it - I can't try to disable it in the code-behind, because the user can still click twice on it. So I'm guessing I need JavaScript.
>
>What confuses me is that I need the onclick event of the save button to run the javascript, as well as run my C# code-behind. Not quite sure of the syntax.
>
>I'm sure it's something simple,but I'm missing it. I'm going to do some google searches, but am also posting, in case anyone has run across this.
>
>Thanks,
>Kevin
Michael McLain
Previous
Reply
Map
View

Click here to load this message in the networking platform