问题
I'm using the following method to add a custom attribute to a check box:
CheckBox chkBx = new CheckBox();
chkBx.ID = "chk" + n;
chkBx.Attributes["itemname"] = strtemPath;
But as a result I'm getting the following HTML:
<span itemname="Some folder"><input id="MainContent_chk0" type="checkbox" name="MasterPg$MainContent$chk0" /></span>
where I'm expecting this:
<input id="MainContent_chk0" type="checkbox" name="MasterPg$MainContent$chk0" itemname="Some folder" />
Any idea how to correct the C# code to get my expected result?
回答1:
Try something like
chkBx.InputAttributes.Add("itemname", strtemPath);
回答2:
Try:
chkBx.Attributes.Add("itemname", strtemPath);
- AttributeCollection.Add Method
来源:https://stackoverflow.com/questions/18075037/add-custom-attribute-to-an-html-input-element-with-c-sharp