Solved

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

Posted on 2006-06-21
3
708 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

18 Experts available now in Live!

Get 1:1 Help Now