473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically created Hidden field

I have the following problem: I’m creating a hidden control dynamically in
the page_load event handler using the following code

C#:
..
HtmlInputHidden Hidden1 = new HtmlInputHidden();
Hidden1.Name = "Hidden1";
Hidden1.Value = "This is the Hidden Value";
this.PlaceHolder.Controls.Add(Hidden1);
..

HTML:
..
<form id="MainForm" method="post" runat="server">
<asp:PlaceHolder Runat="server" ID="PlaceHolder"></asp:PlaceHolder>
</form>
..

I would expect the name of the hidden control in the resulting HTML code
sent to the browser to be “Hidden1”. However, the HTML produced looks like
this:

<input name="_ctl0" type="hidden" value="This is the Hidden Value" />

I there a different way to name the control in code?

Jan 29 '06 #1
2 13667
On Sun, 29 Jan 2006 13:41:27 -0800, cnickl
<cn****@discussions.microsoft.com> wrote:
I have the following problem: Im creating a hidden control dynamically in
the page_load event handler using the following code

C#:
.
HtmlInputHidden Hidden1 = new HtmlInputHidden();
Hidden1.Name = "Hidden1";
Hidden1.Value = "This is the Hidden Value";
this.PlaceHolder.Controls.Add(Hidden1);
.

HTML:
.
<form id="MainForm" method="post" runat="server">
<asp:PlaceHolder Runat="server" ID="PlaceHolder"></asp:PlaceHolder>
</form>
.

I would expect the name of the hidden control in the resulting HTML code
sent to the browser to be Hidden1. However, the HTML produced looks like
this:

<input name="_ctl0" type="hidden" value="This is the Hidden Value" />

I there a different way to name the control in code?


If you want to use your own identifier for a control in ASP.NET you
must set the ID property of the control. The code below will do what
I think you want...

HtmlInputHidden Hidden1 = new HtmlInputHidden();
Hidden1.Name = "Hidden1";
Hidden1.ID = "Hidden1"; // set the id
Hidden1.Value = "This is the Hidden Value";
this.PlaceHolder1.Controls.Add(Hidden1);

Now your source (when viewed from the browser) will look like this:

<input name="Hidden1" type="hidden" id="Hidden1" value="This is the
Hidden Value" />
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Jan 30 '06 #2
Thanks very much, that took care of it.
Jan 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jacek Generowicz | last post by:
I would like some of my _dynamically_ created new-style classes to have instances which are not represented by the standard PyObject, but one which has an extra void* slot which I want to use for...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like this in the aspx:
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
6
by: Amit Maheshwari | last post by:
I have my aspx page on which i am creating <input type=text> on client side using javascript. Now when i submit my page i need to access these controls to get the value entered by the user. the...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.