Hidden Form Field Value Get?

X

xenophon

I add a Hidden form field to my asp.net page in the codebehind, the
Value peoperty is set to 0 and EnableViewState is set to true. Then I
add a LiteralControl with JavaScript that says to set the value to 1.
If I set view the value of th ehidden form field in the debugger
during the course of a PostBack, the value is still set to 0.

Are there any samples of setting a vlaue with JavaScript and reading
the new value in ASP.NET?

Thanks.
 
J

Jeff

Make sure that in your ASPX code that you include runat="server" in your
Hidden form field declaration, like this:
<input id="myHiddenField" type=hidden value="" runat="server">

Then declare it in the code-behind like this:
protected System.Web.UI.HtmlControls.HtmlInputHidden myHiddenField;


Then you can read the value like this (in code-behind):
string hiddenValue = myHiddenField.Value

or set the value like this (in code-behind):
myHiddenField.Value = "whatever";

And client-side you just refer to the hidden field like you normally would:
document.Form1.myHiddenField.value = "whatever";

-HTH
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top