By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

Dropdown List not retaining its SelectedValue

P: n/a
From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.

Jun 27 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ju*********@yahoo.com wrote:
From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.


Did you checked wither "EnableViewState" for this control is set to True?

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".

-
Vadivel Kumar
http://vadivelk.net
Jun 27 '06 #2

P: n/a

Vadivel Kumar wrote:
ju*********@yahoo.com wrote:
From: ju*********@yahoo.com
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Dropdown List not retaining its SelectedValue
Date: Mon, 26 Jun 2006 21:02:57 -0700

Hello,

My dropdown list control does not retain its SelectedValue. Unless I
read the SelectedValue right after the control has been loaded,
populated, and assigned with its original value (and of course that is
the time I absolutely do not need to read it's value) it alwasy returns
"".

I don't think it's a database or database binding issue, because it's
still not working when I tested with unbound dropdown list - the one
that I manually populated with simple integer sequence.

Here's a brief descript of how the application's structured. The main
window / web page creates an instance of this *.ascx class. Just
before the class is loaded in to the browser window, there's another
class that gets loaded first as a page header, where all the common
controls and user interaction pieces are implemented (like buttons and
stuff), and shared by all the *.ascx classes.

Once the head is loaded, all this class does is pretty much to figure
out which User Control to load in, and one of them is my *.ascx User
Control where this problematic dropdown list is in.

It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.

Once user makes a selection on the dropdown list and clicks on Save on
the header, the head class invokes the Save method in the main class,
which in turn calls up the Save method in my User Control. If I look
at the SelectedValue property of my dropdown list within this method
(when it's called), I can see that it has been reset back to "" (and
its selectedIndex has been reverted to 0).

What's weird is that all the other controls, like textboxes and labels,
still retain their values. It's just the dropdown list that gets reset
like this. What is going on????

I also have noticed that if I assign a value to a class variable inside
of the Display method, by the time when I tried to retrieve it in the
Save method, the value of the class variable becomes "undefined". This
makes no sense to me... It almost feels like I am calling methods on
different instacnes of the class, instead of on the same object.

I am very confused. Does this have something to do with one of those
State, Session, Persistance/Non Persistance object thingy that I kept
hearing about? Okay, if that's the case and I am indeed making method
calls on actually different instances of the same class, why am I able
to retrieve the values from some controls, but not this dropdown list?

???

Thank you very much in advance. Any comments and/or feedbacks will be
greatly appreciated.


Did you checked wither "EnableViewState" for this control is set to True?

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".

-
Vadivel Kumar
http://vadivelk.net


Jun 27 '06 #3

P: n/a
First of all, thank you for your reply.
Vadivel Kumar wrote:

Did you checked wither "EnableViewState" for this control is set to True?

Yes, it's been always set to True.

If it is false then the control wont retain its selected value. You also
have to set "AutoPostBack" property of that control to "true".


Well, for some long reason, I really can't set the AutoPostBack
property to True. However, as I said in my original posting, all the
other controls do retain their values and let me read them correctly
later (from inside of other method in the same class), and none of
these controls have AutoPostBack property set to True.

I wish I can try to set the AutoPostBack property to True and see what
happens, but... once I do that it screws up some other stuffs in other
places...

Would there be anything else that I can try?

Have a nice day.

Jun 27 '06 #4

P: n/a
<ju*********@yahoo.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.


Populate your DropDownList in Page_Init instead of Page_Load and all will be
well.
Jun 27 '06 #5

P: n/a

Mark Rae wrote:
<ju*********@yahoo.com> wrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
It's pretty complicated... well, at least for me. Anyway, the first
method (other than those standard initialization methods such as
PageLoad) in this User Control that gets called by the main class is
the Display method that loads all the data in from the database. My
dropdown list is populated here.


Populate your DropDownList in Page_Init instead of Page_Load and all will be
well.


Okay... Actually, I have come across an article that mentioned
something like that (after spending hours searching for my answer in
the Usenet... Well, the problem was that it was a little bit too
complicated to understand. :)

Anyway, the real problem is this: In fact, I'm not even populating the
dropdown list in Page_Load. After the page (UserControl to be more
specific) is loaded into the parent page, the parent page gets all the
data (not just for the dropdown list but all the other controls) from
the database, and calls up a method with a DataSet that contains those
data as a parameter, then the method in the UserControl populates the
dropdown list.

Don't ask me why it's done this way. I am not the creator of this code
- I've only inherited it :( I will give it a try tomorrow. As a
matter of fact, I can't think of why the database queries should happen
at the parent page. Well, actually some parameters for some queries
have to come from outside, in which case the query can't happen in Init
state since the Page/UserControl can't receive those parameters from
its parent before it exists... But, at least for populating dropdown
list, I may be able to do so since all I need to do is retrieving the
entire table with two columns.

Thank you very much for your response. I will post back with how it
went.

Have a nice day.

Jun 29 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.