Error Fetching Custom Attribute Value from HtmlSelect

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
 
G

Guest

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
 
M

mirlisa

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top