Solved

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

Posted on 2006-06-21
3
699 Views
Last Modified: 2008-03-04
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
Comment
Question by:dtburdick
3 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 250 total points
ID: 16951115
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
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16951217
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
 

Author Comment

by:dtburdick
ID: 16954846
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now