By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

Client-Side Hidden Field Update Problem

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)
"Guadala Harry" <GM**@NoSpam.com> wrote in message
news:eI*************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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!

"Guadala Harry" <GM**@NoSpam.com> wrote in message
news:eI*************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.