473,372 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 3030
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 populating from the database (it's viewstate property...
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 besides the first one, the event sucessfully fires....
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 property of the dropdown. Nothing fancy. ...
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 asked by someone else what the autopostback was...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
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 controls are inside a user control and this user...
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 to mimic what is now done with master pages. ...
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 method, refill DropDownList2 and set the focus to...
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 , i.e. except of fist dropdown list no dropdownlist...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.