473,654 Members | 3,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList not maintaining viewstate

I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve
Nov 18 '05 #1
8 5230
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.D ataSource = al;
DropDownList1.D ataBind();

al.Add("dd");
DropDownList2.D ataSource = al;
DropDownList2.D ataBind();
}

[ASPX page]
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t1"
runat="server"> </asp:DropDownLis t>
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t2"
runat="server"> </asp:DropDownLis t>

Brun
"sklett" <as**@fkd.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve

Nov 18 '05 #2
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.D ataSource = al;
DropDownList1.D ataBind();

al.Add("dd");
DropDownList2.D ataSource = al;
DropDownList2.D ataBind();
}

[ASPX page]
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t1"
runat="server"> </asp:DropDownLis t>
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t2"
runat="server"> </asp:DropDownLis t>

Brun
"sklett" <as**@fkd.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve

Nov 18 '05 #3
That is really odd, I have 2-3 pages that all have the opposite behavior.

If I have a dropdownlist with 3 items, a, b, and c

Auto postback set to true

if I select 'b', when the page is rendered after the post back, 'a' is
selected.

I don't know what to do differently...
Thanks for the response though, looks like I have gremlins somewhere ;(
"Bruno Sirianni" <br***********@ virgilio.it> wrote in message
news:5B******** *************@n ews3.tin.it...
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.D ataSource = al;
DropDownList1.D ataBind();

al.Add("dd");
DropDownList2.D ataSource = al;
DropDownList2.D ataBind();
}

[ASPX page]
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t1"
runat="server"> </asp:DropDownLis t>
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t2"
runat="server"> </asp:DropDownLis t>

Brun
"sklett" <as**@fkd.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve


Nov 18 '05 #4
That is really odd, I have 2-3 pages that all have the opposite behavior.

If I have a dropdownlist with 3 items, a, b, and c

Auto postback set to true

if I select 'b', when the page is rendered after the post back, 'a' is
selected.

I don't know what to do differently...
Thanks for the response though, looks like I have gremlins somewhere ;(
"Bruno Sirianni" <br***********@ virgilio.it> wrote in message
news:5B******** *************@n ews3.tin.it...
DropDownList must remember their selection!
I have this example and it works fine...
This page when selected value change make a postback.
Selected value in DropDownList never change.

[C# - CodeBehind]
if (!IsPostBack)
{
ArrayList al = new ArrayList();
al.Add("aa");
al.Add("bb");
al.Add("cc");
DropDownList1.D ataSource = al;
DropDownList1.D ataBind();

al.Add("dd");
DropDownList2.D ataSource = al;
DropDownList2.D ataBind();
}

[ASPX page]
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t1"
runat="server"> </asp:DropDownLis t>
<asp:DropDownLi st AutoPostBack="T rue" id="DropDownLis t2"
runat="server"> </asp:DropDownLis t>

Brun
"sklett" <as**@fkd.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have 2 dropdownlist on a page. They have ViewState = true. After I
submit to the page, the selection in the DropDownList is lost. I set a
break in the Page_Load event to make sure that I wasn't re-binding them
somehow... I'm not. So shouldn't they maintain their selection?

Anything you can think of to check?

Thanks-
Steve


Nov 18 '05 #5
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker </option>
<option value="2">Charl ie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker </option>
<option value="2">Charl ie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7
Jim,

Yeah, that would be a fun one to find ;)
however, that is not the case for me. I set a breakpoint in the page_load
to check what the dropdown list's selected index was and it was correct IE:
if I had selected the 3rd item before postback, the SelectedIndex value was
2

but once the page is rendered... it's back to selecting the first item.

so strange.

Thanks for sharing your situation though, will come in handy some day!
"Jim Corey" <jc****@nospamc harter.net> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker </option>
<option value="2">Charl ie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #8
Jim,

Yeah, that would be a fun one to find ;)
however, that is not the case for me. I set a breakpoint in the page_load
to check what the dropdown list's selected index was and it was correct IE:
if I had selected the 3rd item before postback, the SelectedIndex value was
2

but once the page is rendered... it's back to selecting the first item.

so strange.

Thanks for sharing your situation though, will come in handy some day!
"Jim Corey" <jc****@nospamc harter.net> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
I got stumped for awhile on a similar situation when
I set the item values to something other than the item text.

So for example if the resulting html looked like this:
<option value="2">Abel</option>
<option value="3">Baker </option>
<option value="2">Charl ie</option>

and I selected 'Charlie', when the form posted back
the first item with the selected value (2 in this case)
would display, so 'Abel' would be displayed.

HTH,
Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #9

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

Similar topics

4
5471
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
6
7003
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone changes box1, I want to set the selected index in box2 = 0. When I do this, I dont get an error, but when the page loads, it still has the selected value and not 0. It seems that it is getting the selected value from the viewstate
4
529
by: sklett | last post by:
I have 2 dropdownlist on a page. They have ViewState = true. After I submit to the page, the selection in the DropDownList is lost. I set a break in the Page_Load event to make sure that I wasn't re-binding them somehow... I'm not. So shouldn't they maintain their selection? Anything you can think of to check? Thanks- Steve
10
2735
by: Phuff | last post by:
Thanks in advance! I'm trying to maintain a dl list's selected index on postback. What I'm doing is when a person selects an item from the drop down list I select a date in a calendar control and populate a text box with the date. To do this I set auto postback to the drop down list. But it always resets the selected index on post back. I control for this in the onLoad method... If Not Page.IsPostBack Then If page is posted back...
7
4535
by: AG | last post by:
Hi, ASP.NET 2.0 web app I have a GridView utilizing template columns and bound to an objectdatasource. In the edit template of one column there is a dropdownlist bound to another objectdatasource. The dropdownlist displays the appropriate values when entering edit mode. However when I try to update, I receive the following error.
1
4651
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3492
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
1767
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside a user control (long story). Anyway, the user clicks a save button on the parent control to initiate the postback. The parent then calls a Save method (in the child control) from the button event handler. When I iterate through the datagrid...
6
4269
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 boxes are generating a postback.here is a code . protected void Page_Load(object sender, EventArgs e) { int selected_question = (int)Session; if (!Page.IsPostBack) { display_blueprint(); string...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8707
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.