C# 使用C向HTML输入元素添加自定义属性#
我使用以下方法将自定义属性添加到复选框:C# 使用C向HTML输入元素添加自定义属性#,c#,html,asp.net,web-applications,C#,Html,Asp.net,Web Applications,我使用以下方法将自定义属性添加到复选框: CheckBox chkBx = new CheckBox(); chkBx.ID = "chk" + n; chkBx.Attributes["itemname"] = strtemPath; 但结果我得到了以下HTML: <span itemname="Some folder"><input id="MainContent_chk0" type="checkbox" name="MasterPg$MainContent$chk0"
CheckBox chkBx = new CheckBox();
chkBx.ID = "chk" + n;
chkBx.Attributes["itemname"] = strtemPath;
但结果我得到了以下HTML:
<span itemname="Some folder"><input id="MainContent_chk0" type="checkbox" name="MasterPg$MainContent$chk0" /></span>
我期待的是:
<input id="MainContent_chk0" type="checkbox" name="MasterPg$MainContent$chk0" itemname="Some folder" />
知道如何更正C代码以获得预期结果吗?试试:
chkBx.Attributes.Add("itemname", strtemPath);
chkBx.InputAttributes.Add("itemname", strtemPath);
正如我上面所说,它产生了同样的结果……你明白了,我的朋友。谢谢