A very simple asp.net webform page.
<asp:DronDownList id="ddl" runat="server">
<asp:Button id="btn" runat="server" Text="Do nothing but post back" />
In Page_Load:
if (!IsPostBack)
{
ListItem item = new ListItem("text1","value1");
item.Attributes["custom"] = "CustomValue";
ddl.Items.Add(item);
}
The html it renders:(which looks good)
<select ...>
<option value="value1" custom="CustomValue">text1</option>
</select>
After the button is clicked, I view the source, custom="CustomValue"
is gone.
I know you will say "it's because you put it in a if (!IsPostBack)
block". Of course everything will be ok if I remove the if
statement. But why other STANDARD attributes are rendered? Since I put it in the if
statement, i suppose the output will be:
<select ...></select> // i suppose no options in it!
Why does ASP.NET "choose" attributes?