Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C向HTML输入元素添加自定义属性#_C#_Html_Asp.net_Web Applications - Fatal编程技术网

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);

正如我上面所说,它产生了同样的结果……你明白了,我的朋友。谢谢