HtmlInputText 名称 属性 无效并由 ID 替换
HtmlInputText Name property is not working and replace by ID
我正在从 asp.net 代码隐藏创建一系列输入文本控件。我正在使用下面的代码,但是这段代码没有在输入控件中设置名称属性,而是将 ID 设置为输入控件的名称属性。如何使名称属性与 ID 不同。
HtmlInputText sno = new HtmlInputText();
sno.ID = "txtSno" + j;
sno.Name = "txtSno-name";
sno.Value = snoList[i].ToString();
sno.Attributes.Add("class", "form-control");
cellsno.Controls.Add(sno);
这是渲染的最终 html
<input name="txtSno1" type="text" id="txtSno1" value="1" class="form-control">
预计是
<input name="txtSno-name" type="text" id="txtSno1" value="1" class="form-control">
您无法更改输入的名称属性使用 HtmlInputText 对象的 Name 属性.
如 Microsoft 中所述文档 here
Use the Name property to determine the unique identifier name for an
HtmlInputControl. In this implementation, the get accessor returns the
value of the Control.UniqueID property. However, the set accessor does
not assign a value to this property.
我正在从 asp.net 代码隐藏创建一系列输入文本控件。我正在使用下面的代码,但是这段代码没有在输入控件中设置名称属性,而是将 ID 设置为输入控件的名称属性。如何使名称属性与 ID 不同。
HtmlInputText sno = new HtmlInputText();
sno.ID = "txtSno" + j;
sno.Name = "txtSno-name";
sno.Value = snoList[i].ToString();
sno.Attributes.Add("class", "form-control");
cellsno.Controls.Add(sno);
这是渲染的最终 html
<input name="txtSno1" type="text" id="txtSno1" value="1" class="form-control">
预计是
<input name="txtSno-name" type="text" id="txtSno1" value="1" class="form-control">
您无法更改输入的名称属性使用 HtmlInputText 对象的 Name 属性.
如 Microsoft 中所述文档 here
Use the Name property to determine the unique identifier name for an HtmlInputControl. In this implementation, the get accessor returns the value of the Control.UniqueID property. However, the set accessor does not assign a value to this property.