server side controls disabled in javascript

C

CsaaGuy

I have a requirement to disable some textboxs depending on their
contents. I choose to do this by invoking some javascript. When they
change the contents, i disable the textbox they just put new data into
and focus on another textbox.

My logic works fine, the textboxes get disabled.

However, when the page posts back, the disabled textbox contents (which
were changed before disabling) DOES NOT GO BACK TO THE SERVER. The
server gets the old value instead. I have found some references to this
but I would like to hear some other peoples experences with this. Is it
solveable?
I can solve this by using the Vb.net enable property instead but it
requires a postback which i trying to advoide.

A related queston. VB.net textboxs have their own enable property. The
dom object has it's disabled property. It's the dom object disabled
propety that is causing this behavior. So the quesiton is, can i set
the vb.net textbox.enable property instead of the dom object's version
from Javascript? This would also solve my problem.
 
B

Brock Allen

However, when the page posts back, the disabled textbox contents
(which
were changed before disabling) DOES NOT GO BACK TO THE SERVER. The
server gets the old value instead. I have found some references to
this
but I would like to hear some other peoples experences with this. Is
it
solveable?

This is because ASP.NET is a server side technology and every request tot
he server recreates the page and all the controls on the page. Anything you've
done in the browser in javascript is not known to the server. You can make
this work, but nothing's built in to do this, so i'll be manual. To make
it work you just need to convey the right information to the server and then
write the cde to enable/disable those controls based upon the info you've
sent to the server.
dom object has it's disabled property. It's the dom object disabled
propety that is causing this behavior. So the quesiton is, can i set
the vb.net textbox.enable property instead of the dom object's version
from Javascript? This would also solve my problem.

Yes, you can set that property on the server side control and when it renders
it will emit the right style to make it disabled in the browser. But again,
if you change that value in the browser, you'll have to somehow let the server
know the next time you do a postback so you can keep the client enabled/disabled
state in synch with the server side enabled/disable state.
 
C

CsaaGuy

Thank you very much for responding so quickly. I'm not sure you
answered the question. The problem is with the contents of a control
that was changed then disabled with javascript. On sumit Its contents
are not going back to the server because it's disabled.

And again that you so much for the quick response.
 
C

CsaaGuy

Also, how would you set the textbox.enable=false from javascript?
Remember not the dom.disabled but the vb.net textbox.enable property.
 
C

Chris Botha

How about enabling the text boxes just before submit by also using Java
script. Add a handler to the Form's onsubmit, in the HTML view add something
like this to the form:
<form onsubmit="EnableBoxes();" id="Form1" .....
Then in the function EnableBoxes you enable the boxes that were disabled.
Your function will run before the submit and results will be as expected.
 
B

Brock Allen

Ah, I see what you're saying. Well, it seems you're running into a browser
or HTML issue. Controls that are disabled simply aren't posted to the server.
I don't know if that's specific to the HTML, but it seems to be the case
for both Firefox and IE.
 
C

CsaaGuy

Cool, that worked. Its a kludge but it works! Thanks. My other life
intruded so sorry for the delay. By the way, Is there a way to set the
<asp:TextBox>'s version enabled property from Javascript? Microsoft
worked around this problem by not using the DOM disabled property. They
cheated somehow.

Thanks again.
 
C

Chris Botha

Actually <asp:TextBox> is something that lives only on the server, the stuff
that reaches your browser is HTML, so on the server when rendering, the
output of the MS Controls are converted to their HTML buddies. Do a "View
Source" on the browser to see what the MS control looks like in the browser.
So the answer is no, you can't use Java script to access the MS text box,
because Java script can only access stuff that is in the browser.
 
M

mszanto

Another approach is to make the textbox read-only and change it's class
to one that makes it appear as if its disabled.
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top