I am using Master Pages and I am truing to dynamically add hidden text boxes on the form with the NAMEs that Google Checkout expects.
<input name="item_name_1" type="hidden" value="Widget #1"/>
Using VB.NET, I execute the following code
'Name
Dim hidName As New HtmlInputHidden
hidName.ID = "item_name_" & count.ToString
hidName.Value = item
Form.Controls.Add(hidName)
But because 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_" & count.ToString) and also tried to add the name to the Attributes list. This strangely had no effect on the name attribute whatsoever. When I am not using master pages, I notice that when I set the ID property the NAME is automatically assigned the same value.
Is there a way to control the name of a dynamically added control when you are using master pages?
System.Web.UI.WebControls.Control
has a property called ClientIDMode
.
Instead of HtmlInputHidden
, you may use a 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)
See Making text box hidden in ASP.NET and HiddenField Class.
The ClientIDMode
was introduced in the .Net Framework 4.0.
For earlier versions, an alternative could be adding a 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With