472,342 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 2933
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Manish | last post by:
Hi All, I'm having this problem I hope someone can help provide a solution for it :) I've this dropdown list box in a usercontrol which I'm...
2
by: hypomite | last post by:
I have an handler for the SelectedIndexChanged event of a dropdown box. I have also set the AutoPostBack option to True. When you select any item...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void...
3
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
Hi, Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the...
3
by: Mark B | last post by:
I have an MCMS website that I inherited. It was originally built in .NET 1.1 and then ported to .NET 2.0. They built it with inherited base classes...
3
by: =?Utf-8?B?Y21lZWsxXzE5OTk=?= | last post by:
Hello, On a webpage, create an UpdatePanel with two DropDownLists. Set AutoPostBack of DropDownList1 to true. In the SelectedIndexChanged...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs ,...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.