Reputation: 722
I have a CheckBoxList on WebFrom
<asp:CheckBoxList id="chkList" runat="server">
</asp:CheckBoxList>
now the Control is populated on server side some thing like this
DataTable dt = myDatasource
foreach(DataRow dr in dt.Rows)
{
ListItem li = new ListItem();
li.Attributes.Add("class", (string)dr["CssClass"]);
//........ Some More Properties.....
chkList.Items.Add(li);
}
after this i need to disable the some checkboxes on basis of some condition
foreach(ListItem item in chkList.Items)
{
if (// Some Condition)
{
item.Enabled = false;
}
}
now the issue is when item.Enabled = false the class attribute is override by
class = "aspNetDisabled";
and the class that is applied at the time of populating no more.
i need that class to do some processing in javascript.
Upvotes: 2
Views: 1891
Reputation: 19486
Try setting your class using CssClass instead of class.
I'm using .NET 4.5.1.
I've tested this and it appears that if you have the class attribute set, .enabled = false
will overwrite the class property with aspNetDisabled. However, if you have the CssClass set, that value will be merged with aspNetDisabled.
Note: I see you are setting class with this line of code:
li.Attributes.Add("class", (string)dr["CssClass"]);
However, I should note that I'm seeing the same behavior when I have class set instead of CssClass in the markup.
Upvotes: 1
Reputation: 6925
I had similar issue. In my case on disabled elements was applied that aspNetDisabled class and all disabled controls had wrong colors. So, I used jquery to remove this class on every element/control I wont and everything works and looks great now.
This is my code for removing aspNetDisabled class:
$(document).ready(function () {
$("span").removeClass("aspNetDisabled");
$("select").removeClass("aspNetDisabled");
$("input").removeClass("aspNetDisabled");
});
Upvotes: 2