• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 756
  • Last Modified:

How to set hidden field values on forms that don't runat="server"?

I've been using the following method for hidden fields:

Page.RegisterHiddenField("HiddenField1","foobar");

I need to post to an external site, so I'm using an HTML submit button.  I need to turn off runat="server" or else the page posts back to itself.  When I do, the RegisterHiddenField code stops working.

I was told I could use the following to create hidden fields:

<asp:HiddenField ID="HiddenField1" runat="server" Value="foobar" />

But that gives me an "Error Creating Control" message saying HiddenField isn't part of the WebControls assembly, probably because I'm using .NET 1.1, but that's what I'm stuck with because I'm using VS 2003.

Is there another way to create a hidden field to which I can dynamically assign values when the page is loaded?

Thanks folks.  This is the last big piece of this application I need to get working.
0
dtburdick
Asked:
dtburdick
1 Solution
 
nauman_ahmedCommented:
The syntax for hidden field is given below:

<input type=hidden name="fieldName" value="value" runat=server>

There is nothing in VS.NET as asp:HiddenField. I will recommend declaring this field in the ASPX and not adding it in the code-behind. In the code-behind you can set the value as follows:

hiddenField.value = "value"

From javascript its document.forms[0].hiddenFieldName.value = "new Value";

-Nauman.
0
 
GavinMannionCommented:
You can always just use a normal textbox and make it's visible attribute = false....

It should then work as a normal field..

But if it doesn't need to be dynamic or anything just use the html standard.... as shown above
0
 
dtburdickAuthor Commented:
Thank you!  I was running out of hope!

The only thing I'll add is that I needed to identify the object at the top of the .CS page:

protected System.Web.UI.HtmlControls.HtmlInputHidden MYHIDDENOBJECT;

and that the code to modify the contents is case sensitive so it is:

MYHIDDENOBJECT.Value="foobar";

Much thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now