|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
January 9th, 2007, 06:12 PM
|
Authorized User
|
|
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Disable a button
I have a Save button on a web page.
I want to disable the button when clicked, so that the user does not click it more than once, as the serevr side code is being processed.
i disabled the button by calling a javascript function -
btnSave.Attributes.Add("onClick","return buttonDisabled();") ;
In the Javascript file i have -
function disableButton()
{
var btnSave = document.getElementById('btnSave') ;
btnSave.disabled = true ;
return true ;
}
since the button gets disabled my server side code(in C#) does not get executed.
thanks a lot for any kind of help
|
January 9th, 2007, 08:15 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Your code needs to be something like this:
if(typeof(Page_ClientValidate) == 'function'){
if(Page_ClientValidate() == false){return false;}}
this.value = 'Please Wait...';
Page.GetPostBackEventReference(this.btnSubmit));
Create a string, in code, with the above javascript code then call
btnSave.Attributes.Add("onclick", [above string value])
hth
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
January 11th, 2007, 03:04 AM
|
Authorized User
|
|
Join Date: May 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
disable the button from server side in btnSave_Click -> btnSave.Enable=false;
Regards,
Rashida Jabeen
http://www.akaas.net
|
January 11th, 2007, 09:40 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
That wont work rashida because doing it that way would only disable the button AFTER the method it calls finished executing he needs it to be disabled WHILE the method is executing.
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
January 11th, 2007, 03:19 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by dparsons
if(typeof(Page_ClientValidate) == 'function'){
if(Page_ClientValidate() == false){return false;}}
this.value = 'Please Wait...';
Page.GetPostBackEventReference(this.btnSubmit));
|
There's a slight error in there. There is some .NET code in the javascript.
The important part is that you use
Code:
Page.GetPostBackEventReference(btnSubmit));
to generate the client side method that performs the postback.
The simplest implementation could look like this:
Code:
strClickJS = string.Format("this.disabled=true;{0}", Page.GetPostBackEventReference(this.btnSubmit));)
btnSave.Attributes.Add("onClick", strClickJS);
If you want to also take care of validation, then you can add in the validation part of the javascript from dparsons' post.
- Peter
|
January 12th, 2007, 03:34 AM
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Parsons/Peter
How bout using the JS function below on button click, which will fullful the requirement:
function DisableButton(obj)
{
document.getElementById(obj).disabled = true;
__doPostBack("btnSubmit","");
}
Regards
Mike
Fortune favours the brave, so don't regret on missed oppurtunities.
|
January 12th, 2007, 09:38 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Ahhh the beauty of programming, so many ways to accomplish the same task ^^
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|
|