HiddenField value not valid

S

sklett

I've added a HiddenField control to my page and some javascript to show it's
value in an alert box when a button is pressed. The value that is displayed
in the alert box is correct, but when I post the form the value for the
HiddenField control is empty.

I'm pretty new to ASP.net so I'm not really sure what could cause this.

I'm using client side javascript to set the value in the HiddenField, not
sure if that matters.

Any ideas?

Thanks for reading,
Steve
 
S

Siva M

I am not sure how you access the HiddenField control on the client side.
Remember the ID assigned to the ASP.NET controls on the client side are
different than those used on the server side. Make sure you use the
..ClientID property of the control to get the client side ID for use in
JavaScript.

I've added a HiddenField control to my page and some javascript to show it's
value in an alert box when a button is pressed. The value that is displayed
in the alert box is correct, but when I post the form the value for the
HiddenField control is empty.

I'm pretty new to ASP.net so I'm not really sure what could cause this.

I'm using client side javascript to set the value in the HiddenField, not
sure if that matters.

Any ideas?

Thanks for reading,
Steve
 
R

Robert Haken [MVP]

I've added a HiddenField control to my page and some javascript to show
it's value in an alert box when a button is pressed. The value that is
displayed in the alert box is correct, but when I post the form the value
for the HiddenField control is empty.

I'm pretty new to ASP.net so I'm not really sure what could cause this.

I'm using client side javascript to set the value in the HiddenField, not
sure if that matters.

Any ideas?

Make sure, the hidden-field is not "disabled" on client-side. Data of
disabled <input>s are not sent with POST.
You can use atribute Trace="true" in <%@ Page %> directive to see what the
POST data are.
Also make sure, that the hidden-field is inside the <form> tag.

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top