How to assign a specific name to a tag when using master pages?

I use master pages and I want to dynamically add hidden text fields to the form with the NAMES that Google Checkout expects.

<input name="item_name_1" type="hidden" value="Widget #1"/>

Using VB.NET, I am executing the following code

'Name
Dim hidName As New HtmlInputHidden
hidName.ID = "item_name_" & count.ToString
hidName.Value = item
Form.Controls.Add(hidName)

But since I use master pages, the control is renamed to "ctl00 $ item_name_1".

<input name="ctl00$item_name_1" type="hidden" id="ctl00_item_name_1" 

Note that I tried to set the Name property (hidName.Name = "item_name_" and count.ToString), and also tried to add the name to the attribute list. This strangely did not affect the name attribute. When I do not use the master page, I notice that when I set the ID property, the user NAME is assigned the same value.

Is there a way to control the name of a dynamically added control when using master pages?

+5
2

System.Web.UI.WebControls.Control , ClientIDMode.
HtmlInputHidden HiddenField.

 'Name
Dim hidName As New System.Web.UI.WebControls.HiddenField
hidName.ID = "item_name_" & count.ToString
hidName.ClientIDMode = System.Web.UI.ClientIDMode.Static
hidName.Value = item
Form.Controls.Add(hidName)

. ASP.NET HiddenField Class.

ClientIDMode .Net Framework 4.0.
asp:Literal.

 'Name
Dim hidName As New System.Web.UI.WebControls.Literal
hidName.Text = _
  String.Format("<input name=""item_name_{0}"" type=""hidden"" value=""{1}""/>", _
                count, item)
Form.Controls.Add(hidName)
+1

, № . , . - , :

Dim hidName As New HtmlInputHidden
hidName.Attributes("Name") = "item_name_" & count.ToString
hidName.Value = item
Form.Controls.Add(hidName)
0

All Articles