Changing web control values from Javascript

M

Marcus

Hi,

I have a strange problem here... I have a simple onclick event on an
ASP.NET button that does the following Javascript...

document.getElementById("Button1").text = "Cancelled";

However, when I inspect the Button1.text value from code behind the it
shows the original value of Button1 and not what the Javascript has
changed it to. The funny thing is that it works for an ASP.NET text
box, as follows:-

document.getElementById("TextBox1").value = "Marcus123";

Any help appreciated....

Marcus.
 
G

Greg Burns

"Form controls, such as TextBox and RadioButtonList, retain their values
between posts even when view state is disabled. The values of these
controls do not need to be preserved in the _VIEWSTATE hidden form field
becuase they are actually being submitted to the server on each form
post." - ASP.NET Unleashed

Sounds like to me the Textbox value is getting submitted to the server
automatically during post while the button text is discarded. Viewstate
isn't really involved here, since these values are being changed client
side. I only quoted that because it seems relevant in the description of
how a textbox is "different".

HTH,
Greg
 
M

Marcus Wade

Thanks Greg,

Strangely, it also doesn't work with label, literal and Radio form
controls either (Only a textbox form control). Even stranger, it "does"
work with a hidden HTML Text Box (with runat=server) but not with HTML
Radio Buttons (With runat=server).

Trial and error seems to be the idea with this one!

Let me know if you discover anything else.

Thanks,

Marcus
 

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

Top