473,327 Members | 2,081 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,327 software developers and data experts.

dropdown list selecteditem changes after page.unload event

Hi,

I have been struggling with an unusual problem with a
dropdownlist web control for quite some time now.
Cutting straight to the problem, I am setting the
selected item in the dropdownlist using the IndexOf
method of the list's items collection (in my debugging
case this successfully sets the selectedindex to 15).
After postback, the selecteditem is always the first item
in the list, losing the selection I set previously (And
yes, enableviewstate is turned OFF for the control, and
the whole page as well). I set a breakpoint in the
page.unload event to check once more what the
selectedindex of the dropdown was, just to make sure I
was not accidentally resetting it elsewhere in code, but
the selecteditem was still set correctly (to 15) at this
point. Frustrated, I set a breakpoint in global.asax's
Global_PostRequestHandlerExecute, where the selectedindex
had mysteriously reset to 0. My question is: What could
possibly happen after page.unload and before
Global_PostRequestHandlerExecute to change the
selectedindex of this list? I have seen viewstate do
similar things but i have made certain that it is not on.

Thanks,

Justin Bartels
Nov 17 '05 #1
4 3919
Are you trying to only select the index to 15 on the first page load ?

Is so, do the selection of the item in an if/then/pageispostback block.
David Wier
http://aspnet101.com
http://aspexpress.com
"Justin Bartels" <sm***@spam-someone-else.net> wrote in message
news:05****************************@phx.gbl...
Hi,

I have been struggling with an unusual problem with a
dropdownlist web control for quite some time now.
Cutting straight to the problem, I am setting the
selected item in the dropdownlist using the IndexOf
method of the list's items collection (in my debugging
case this successfully sets the selectedindex to 15).
After postback, the selecteditem is always the first item
in the list, losing the selection I set previously (And
yes, enableviewstate is turned OFF for the control, and
the whole page as well). I set a breakpoint in the
page.unload event to check once more what the
selectedindex of the dropdown was, just to make sure I
was not accidentally resetting it elsewhere in code, but
the selecteditem was still set correctly (to 15) at this
point. Frustrated, I set a breakpoint in global.asax's
Global_PostRequestHandlerExecute, where the selectedindex
had mysteriously reset to 0. My question is: What could
possibly happen after page.unload and before
Global_PostRequestHandlerExecute to change the
selectedindex of this list? I have seen viewstate do
similar things but i have made certain that it is not on.

Thanks,

Justin Bartels

Nov 17 '05 #2
Are you trying to only select the index to 15 on the first page load ?

Is so, do the selection of the item in an if/then/pageispostback block.
David Wier
http://aspnet101.com
http://aspexpress.com
"Justin Bartels" <sm***@spam-someone-else.net> wrote in message
news:05****************************@phx.gbl...
Hi,

I have been struggling with an unusual problem with a
dropdownlist web control for quite some time now.
Cutting straight to the problem, I am setting the
selected item in the dropdownlist using the IndexOf
method of the list's items collection (in my debugging
case this successfully sets the selectedindex to 15).
After postback, the selecteditem is always the first item
in the list, losing the selection I set previously (And
yes, enableviewstate is turned OFF for the control, and
the whole page as well). I set a breakpoint in the
page.unload event to check once more what the
selectedindex of the dropdown was, just to make sure I
was not accidentally resetting it elsewhere in code, but
the selecteditem was still set correctly (to 15) at this
point. Frustrated, I set a breakpoint in global.asax's
Global_PostRequestHandlerExecute, where the selectedindex
had mysteriously reset to 0. My question is: What could
possibly happen after page.unload and before
Global_PostRequestHandlerExecute to change the
selectedindex of this list? I have seen viewstate do
similar things but i have made certain that it is not on.

Thanks,

Justin Bartels

Nov 17 '05 #3
Hi Justin,

Firstly I want to thank David for his great help in this issue.

Based on my research and experience, I would like to share the following
information with you.

ASP.NET uses the Control.ViewState property provides a dictionary object
for retaining values between multiple requests for the same page, which
uses a HTML-standard hidden fields to store any page-specific information
in the page.

However, to make use of this new future, we should enable this
functionality by setting the EnableViewState property to True on the
control whose states want to be maintained.

In this case, the current state in the dropdownlist control will not be
overridden in the unload phrase until the page object tries to reload the
viewstate on the web page. Since the EnableViewState properties on all
controls on this page were disabled, what stored in viewstate is the
original information when the web page was loaded first time. That is why
each time the web page posts back, the dropdownlist control lost the
selected item before submit occurs.

To resolve the problem in this case, there are two ways,

1. Just enable the EnableViewState properties on controls whose states want
to be maintained. Nothing else we should do.

2. Get the selectedItem in each post back and re-assign it to the
dropdownlist control in the later phrase of the page lifecycle. With this
way, we may have to add a couple of code, as what we do in the traditional
ASP world.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
Hi Justin,

Firstly I want to thank David for his great help in this issue.

Based on my research and experience, I would like to share the following
information with you.

ASP.NET uses the Control.ViewState property provides a dictionary object
for retaining values between multiple requests for the same page, which
uses a HTML-standard hidden fields to store any page-specific information
in the page.

However, to make use of this new future, we should enable this
functionality by setting the EnableViewState property to True on the
control whose states want to be maintained.

In this case, the current state in the dropdownlist control will not be
overridden in the unload phrase until the page object tries to reload the
viewstate on the web page. Since the EnableViewState properties on all
controls on this page were disabled, what stored in viewstate is the
original information when the web page was loaded first time. That is why
each time the web page posts back, the dropdownlist control lost the
selected item before submit occurs.

To resolve the problem in this case, there are two ways,

1. Just enable the EnableViewState properties on controls whose states want
to be maintained. Nothing else we should do.

2. Get the selectedItem in each post back and re-assign it to the
dropdownlist control in the later phrase of the page lifecycle. With this
way, we may have to add a couple of code, as what we do in the traditional
ASP world.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5

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

Similar topics

1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
0
by: E . | last post by:
I seem to be getting nowhere with this problem here is the situation. I have a webform with a data grid populated with the results of a table that has only 3 fields. Then below that are 1...
4
by: Mira Vizjak | last post by:
Hi I'm using a datagrid with a dropdown list in it. The dropdown list is filled with values from SQL database, it's autopostback property is set to true and when I select another item in it, the...
0
by: Justin Bartels | last post by:
Hi, I have been struggling with an unusual problem with a dropdownlist web control for quite some time now. Cutting straight to the problem, I am setting the selected item in the dropdownlist...
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
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...
4
by: msch-prv | last post by:
I get a runtime error 'NullReferenceException: Object reference not set to an instance of an object' when I attempt to execute sub UpdGrd() in the Page_Load event. UpdGrd() basically creates a grid...
3
by: =?Utf-8?B?SmF2YW1hbjU5?= | last post by:
I have an ASP.NET example which programmatically builds a drop down list. public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DropDownList ddlCategories; public...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.