Error Fetching Custom Attribute Value from HtmlSelect

  • Thread starter Thread starter mirlisa
  • Start date Start date
M

mirlisa

I'm using an HtmlSelect (runat=sever).

I add the items programmatically and I also add a custom attribute to
each listitem because I need to track an additional field value.

I'm having a problem getting that attribute value upon postback. I keep
getting a null reference error. I was under the impression that the
attribute collection is saved in viewstate.

My code to get the attribute value is:

string val=
mySelect.Attributes["attrname"][mySelect.SelectedIndex].ToString();

What am I doing wrong?

Thanks.
Lisa
 
I am not sure that your assumption is correct. Viewstate does not normally
hold values in controls, only changes in control state.
if you have programmatically added items to a control and the page is posted
back, they would need to be re-created.
Peter
 
Thanks, Peter.

My assumption was incorrect as you said. I have decided to handle this
process a different way without using attributes.

I am not sure that your assumption is correct. Viewstate does not normally
hold values in controls, only changes in control state.
if you have programmatically added items to a control and the page is posted
back, they would need to be re-created.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




mirlisa said:
I'm using an HtmlSelect (runat=sever).

I add the items programmatically and I also add a custom attribute to
each listitem because I need to track an additional field value.

I'm having a problem getting that attribute value upon postback. I keep
getting a null reference error. I was under the impression that the
attribute collection is saved in viewstate.

My code to get the attribute value is:

string val=
mySelect.Attributes["attrname"][mySelect.SelectedIndex].ToString();

What am I doing wrong?

Thanks.
Lisa
 
Back
Top