Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem accessing hidden form field on postback

Status
Not open for further replies.

xtremeLogic

Programmer
Dec 19, 2003
53
CA
Hi,

I have a hidden form field that I use to keep track of some client side changes in my aspx page:
Code:
<input type="hidden" id="hdDeliveryMethod" value="delivery">

However, when I try to read the value of the control on postback, I get a null reference:
Code:
Dim strDeliveryMethod As String = Request.Params("hdDeliveryMethod")
When I run a debug on this line, I get strDeliveryMethod = Nothing. I have also done some Watches to check Request.Params and Request.Form but I can't seem to find my hidden control in the list.

I would really appreciate it if someone could tell me how to get the value of a hidden form field on postback.

Thanks,
 
Add the name attribute

<input type="hidden" id="hdDeliveryMethod" name="hdDeliveryMethod" value="delivery">

This should get you what you want
Request.Form("hdDeliveryMethod")
 
fyi, i figured out how to access the hidden field using:
Code:
Request.Form.Get("hdDeliveryMethod")
 
You might also prefer to add a runat=server attribute to the control and instantiate it in the code-behind, or, easier yet, a drag a hidden control from the HTML tab in the toolbox, right-click it and select "run as server control".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top