473,466 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error Fetching Custom Attribute Value from HtmlSelect

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

Aug 25 '06 #1
2 1543
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" wrote:
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

Aug 25 '06 #2
Thanks, Peter.

My assumption was incorrect as you said. I have decided to handle this
process a different way without using attributes.
Peter wrote:
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" wrote:
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
Aug 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fuzzyman | last post by:
I've written a CGI proxy that remotely fetches web pages. I use the urlopen function in CLientCookie which replaces (and ultimately uses) the urlopen function in urllib2. What I'd like to do is...
6
by: BK | last post by:
I'm having a really strange problem with and HtmlSelect server control (listbox) and a RequiredFieldValidator that I am trying to use to make sure that someone has items in the listbox. The way...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
4
by: tommy | last post by:
hello everbody, i write a little asp-application with forms-authentication. i copy my aspx-files with web.config to my webspace and i get the error above... i tried to set the...
0
by: Darren | last post by:
Hi, I get the above error message when I try to run my page on the remote server. As I am a newbie with .net, I chose Project | Copy to copy the files needed to a seperate local directory then...
0
by: Adam Getchell | last post by:
I'm attempting to write a custom Authentication module using http://www.15seconds.com/Issue/020417.htm I looked at http://support.microsoft.com/default.aspx?scid=kb;EN-US;307996, but it doesn't...
1
by: writebrent | last post by:
This is my code: HtmlSelect m = new HtmlSelect(); m.ID = "m1"; m.DataSource = dvBasic; //DataView created elsewhere m.DataTextField = "value"; m.DataValueField = "key"; m.Value = "2";...
5
by: =?Utf-8?B?cGFnYXRlcw==?= | last post by:
Hello All, I am sure that I am just overlooking something, but here's something I can't quite get right... I want to be able to get the value of a parameter of an unknown custom attribute at...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.