Problems with disabling ASP.NET controls using javascript

J

john

I have two different problems:

1. When the user has clicked on a button that is causing the browser
to post back to the server, it could take a little while for the new
page to show up. So in the mean time, I want to change the cursor to
an hourglass and disable all of the controls on the form using
javascript so the user can't do anything with any of the controls on
the page. But when I disable certain controls (e.g. text boxes, radio
buttons, etc.) then their value/state doesn't get saved after it posts
back.

2. When I disable a link (i.e. one created with a LinkButton control)
using javascript, it gets grayed out, but the user can still use it.
In other words, it looks disabled, but the user can still click on it
and the page goes to the link. On the other hand, if I disable a link
on the server side by setting the control's Enabled property to false,
then it ends up completely disabled like you would expect. I think the
reason that in this case it's competely disabled is that not only does
the html that is generated have disabled="disabled" in the tag, but
there is no href in the tag. If I try to change the href to '' with
javascript, it doesn't do the same thing.

Any ideas?
Thanks in advance.
 
B

bruce barker

1) browsers do not postback any disabled form controls. As you are setting
the controls disabled before the actual postback, this is why the values are
cleared. from the server's point of view, it looks like they were cleared.

2) as an anchor is not a form control, it does not support disabled. to
disable a link in client script, try the following:

document.getElementById('myLink').onclick = function(){ return false;};

this will cancel the link request.


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top