469,609 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Problem with Dropdown - ViewState and AutoPostBack

I have a page that works fine. I am trying to optimize the page by
overriding some of the Information that is being saved in the hidden
VIEWSTATE.

If I make the properties of the dropdown False for ViewState and True for
AutoPostBack, it does reload the page but does not call the
SelectedIndexChanged event. If I put the ViewState to True then it is
called.

Does this mean that I cannot get that event and deal with it in better code
than what is required by using both the ViewState and AutoPostBack to true.
I want to cache some info so that is retrieved only when necessary not on
every page load.

Nov 17 '05 #1
3 2824
More info. A small project with a button and a listbox (ViewState =
"False") causes the following. If I click the listbox to change the
selection nothing happens. If I then click the button first the
ListBoxSelection Change happens then the Button Click.

Does this mean that the only way to get the listbox to send events (when
they happen) is to have the view state enabled??

If so I can only see this as a problem if you are trying to optimize the
code for page loads.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message
news:ha*********************@news04.bloor.is.net.c able.rogers.com...
I have a page that works fine. I am trying to optimize the page by
overriding some of the Information that is being saved in the hidden
VIEWSTATE.

If I make the properties of the dropdown False for ViewState and True for
AutoPostBack, it does reload the page but does not call the
SelectedIndexChanged event. If I put the ViewState to True then it is
called.

Does this mean that I cannot get that event and deal with it in better code than what is required by using both the ViewState and AutoPostBack to true. I want to cache some info so that is retrieved only when necessary not on
every page load.

Nov 17 '05 #2
By default, the autopostback property of non-button type controls is set to
false. Without a post back your selection change event will not fire until
the next post back. When a form is posted back, all pending events are
processed. This is why the selection change happens as well as the button
click when you click it. To make the page process the selection change box
immediately, you need to set the autopostback property of the listbox to
true. This is completely unrelated to the viewstate.

I was minding my own business when Lloyd Sheen blurted out:
More info. A small project with a button and a listbox (ViewState =
"False") causes the following. If I click the listbox to change the
selection nothing happens. If I then click the button first the
ListBoxSelection Change happens then the Button Click.

Does this mean that the only way to get the listbox to send events (when
they happen) is to have the view state enabled??

If so I can only see this as a problem if you are trying to optimize the
code for page loads.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message news:ha*********************@news04.bloor.is.net.c able.rogers.com...
I have a page that works fine. I am trying to optimize the page by
overriding some of the Information that is being saved in the hidden
VIEWSTATE.

If I make the properties of the dropdown False for ViewState and True for
AutoPostBack, it does reload the page but does not call the
SelectedIndexChanged event. If I put the ViewState to True then it is
called.

Does this mean that I cannot get that event and deal with it in better code than what is required by using both the ViewState and AutoPostBack to true. I want to cache some info so that is retrieved only when necessary not on
every page load.


--
Insert corny line here
Nov 17 '05 #3
JD
With the listbox, the items are saved in the viewstate. So the first time
your page is rendered you add the items to the listbox and everything is
fine. When a postback happens Load View State takes place, which repopulates
the listbox with the items that the listbox originally contained. Then after
this Load Postback Data happens which applies the user's selection to the
list box. If a selection took place, then the event will be fired latter on
in the page processing.

When you don't have viewstate enabled, on Load View State nothing in the
ListBox is repopulated, and when Load Postback Data happens the user
selection comes in but there are no items in the Listbox to apply the user
selection to, hence no event. If you don't want to use viewstate, you have
to repopulate the listbox yourself before Load Postback Data happens.
Essentailly you are taking over the view states responsibility but the data
is coming from server side cache, database, file, etc...
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message
news:OG***************@news01.bloor.is.net.cable.r ogers.com...
More info. A small project with a button and a listbox (ViewState =
"False") causes the following. If I click the listbox to change the
selection nothing happens. If I then click the button first the
ListBoxSelection Change happens then the Button Click.

Does this mean that the only way to get the listbox to send events (when
they happen) is to have the view state enabled??

If so I can only see this as a problem if you are trying to optimize the
code for page loads.
"Lloyd Sheen" <sq*******************@tostopspamhotmail.com> wrote in message news:ha*********************@news04.bloor.is.net.c able.rogers.com...
I have a page that works fine. I am trying to optimize the page by
overriding some of the Information that is being saved in the hidden
VIEWSTATE.

If I make the properties of the dropdown False for ViewState and True for AutoPostBack, it does reload the page but does not call the
SelectedIndexChanged event. If I put the ViewState to True then it is
called.

Does this mean that I cannot get that event and deal with it in better

code
than what is required by using both the ViewState and AutoPostBack to

true.
I want to cache some info so that is retrieved only when necessary not on every page load.


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Manish | last post: by
2 posts views Thread by Mike Collins | last post: by
3 posts views Thread by =?Utf-8?B?ZGVuIDIwMDU=?= | last post: by
3 posts views Thread by Mark B | last post: by
3 posts views Thread by =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.