Client-Side Hidden Field Update Problem

G

Guadala Harry

In an aspx file I have declared a hidden field like this:
<input id="hTestVal" type=hidden value="-1" runat="server">

Defined in the code-behind like this:
protected System.Web.UI.HtmlControls.HtmlInputHidden hTestVal;

In client-side JavaScript I set the value like this:
document.all("hTestVal").Value = "yo";

The problem is that the value of the hidden field (hTestVal) does not get
updated (It is not updated on Postback, and when I view the source of the
rendered aspx page in IE6, the value is still "-1" even though the
client-side script has executed (to set the value to "yo").

I believe the value is in fact getting updated in the client, because the
following line, when executed immediately after setting the value to "yo"
produces the/that new value:
alert(document.all("hTestVal").Value);

FWIW, the hidden control is declared within a form, like this:
<form id="Form1" method="post" runat="server">

I'm confused because I have a virtually identical setup in other pages in my
site and those hidden fields and client-side value changes work just fine...
meaning that the value set in the client-side script shows up in the control
on the server during postback as expected.

What could be the deal? I need to receive the updated value (e.g., "yo") in
the server on postback.

Thanks
 
B

bruce barker

input controls do not have a "Value" property, so your client code creates
one and sets the its value, the alert displays the value of this new
property. try updating the "value" property, which is what the control posts
back.

also you are using obsolete dom methods, which future ms browsers may not
support.

try:

document.getElementById("hTestVal").value = "yo";

which works with all w3c compliant browsers.

-- bruce (sqlwork.com)
 
G

Guadala Harry

In continuing to research this, one difference between the pages that work
and the "problem page" (as described in the original post) is that the
"problem page" is rendered within a frame(set). Could this be relevant? NOTE
that all the code in question (client-side and code-behind) is all for the
same aspx page - and not between pages in the frameset. In other words, I'm
*not* trying to read the hidden field from another page's code-behind.

Still looking for a direction to go with this... Thanks!
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top