disabling controls during the postback...

  • Thread starter Thread starter Dan =o\)
  • Start date Start date
D

Dan =o\)

Hi guys,

in the scenario where a user fills in a form, and clicks on a button to
Save, there's a period of waiting (the slower the connection between client
and server, the longer the delay) where the user may be oblivious and could
say, press the button twice, or even fill in some more data on the form...

When the postback completes, any data entered in during this delay is lost.

How do I, when the user clicks on a button, process that event and then
disable the controls instantly so no more things can be done until the
postback is complete?

If you do it client side, surely the turning it off will disable the server
side event from being processed?
If you do it server side, then you have to wait for the postback cycle, and
this sort of makes the whole thing pointless.

Thanks.

Dan.
 
What about simply disabling the button onclick?

btn.Attributes.Add("onClick", "this.disabled = true;");

Karl
 
Karl,

Unfortunately not...

For two reasons:
- the first is that performing this action then prevents the server side
event from firing and so there is no postback, and therefore no execution of
the code attached to the button...
- the second this is only one control, i want to "disable" the whole screen
while this is happening so the user cannot inadvertantly added more data in
the postback period.

Thanks.

Dan.
 
Hi

I use a javascript code to do this job. I don't know if this is the simplest
solution but it's really working.

make a js file in which put javascript like this

function DisableControls(){
document.body.style.cursor = "wait";
nr = document.forms[0].all.length;
for(i=0;i<nr;i++){
if(document.forms[0].all(i).tagName == "SELECT" ||
(document.forms[0].all(i).tagName == "INPUT" &&
(document.forms[0].all(i).type == "radio" || document.forms[0].all(i).type ==
"checkbox" || document.forms[0].all(i).type == "button") ))
document.forms[0].all(i).disabled = true;
}
}

In your code behind attach event onbeforeunload with this king of code
RegisterStartupScript("onbeforeunload", "<script
language=\"JavaScript\">window.attachEvent(\" onbeforeunload\",function
(){DisableControls()});</script>");

and also attachjs file with this

RegisterClientScriptBlock("Include", "<script language=\"Javascript\" src=\"
Scripts/Common.js\"></script>");

Hope this helps.
 
PERFECT!

Thanks for that.

Psycho said:
Hi

I use a javascript code to do this job. I don't know if this is the
simplest
solution but it's really working.

make a js file in which put javascript like this

function DisableControls(){
document.body.style.cursor = "wait";
nr = document.forms[0].all.length;
for(i=0;i<nr;i++){
if(document.forms[0].all(i).tagName == "SELECT" ||
(document.forms[0].all(i).tagName == "INPUT" &&
(document.forms[0].all(i).type == "radio" || document.forms[0].all(i).type
==
"checkbox" || document.forms[0].all(i).type == "button") ))
document.forms[0].all(i).disabled = true;
}
}

In your code behind attach event onbeforeunload with this king of code
RegisterStartupScript("onbeforeunload", "<script
language=\"JavaScript\">window.attachEvent(\" onbeforeunload\",function
(){DisableControls()});</script>");

and also attachjs file with this

RegisterClientScriptBlock("Include", "<script language=\"Javascript\"
src=\"
Scripts/Common.js\"></script>");

Hope this helps.

Dan =o) said:
Hi guys,

in the scenario where a user fills in a form, and clicks on a button to
Save, there's a period of waiting (the slower the connection between
client
and server, the longer the delay) where the user may be oblivious and
could
say, press the button twice, or even fill in some more data on the
form...

When the postback completes, any data entered in during this delay is
lost.

How do I, when the user clicks on a button, process that event and then
disable the controls instantly so no more things can be done until the
postback is complete?

If you do it client side, surely the turning it off will disable the
server
side event from being processed?
If you do it server side, then you have to wait for the postback cycle,
and
this sort of makes the whole thing pointless.

Thanks.

Dan.
 
Back
Top