2

I am generating ListItems for a CheckBoxList control in ASP, but when I do something like the following:

...
Dim newListItem As ListItem = New ListItem("RoleName")
newListItem.Attributes.Add("style", "color:blue;")
CheckBoxListControlToFill.Items.Add(newListItem)
...

"RoleName" is maintained from post back to post back, but my style tag is dropped after the first post back. If I want to keep any attribute like this, do I need to re-add it every post back?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64

1 Answers1

2

The attributes will be lost after a postback. The question below links to a blog post that contains code that will persist attributes to the view state, the code is in c# though -

ListItems attributes in a DropDownList are lost on postback?

Community
  • 1
  • 1
ipr101
  • 24,096
  • 8
  • 59
  • 61