Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 6th, 2006, 05:32 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Cannot have multiple items selected in a DropDownL

Does anybody have a clue for me how to figure out which of a myriad of drop down lists is experiencing this problem? The error page seems to give no indication AFAIC see:

Cannot have multiple items selected in a DropDownList.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
   System.Web.UI.WebControls.DropDownList.VerifyMulti Select() +133
   System.Web.UI.WebControls.ListControl.RenderConten ts(HtmlTextWriter writer) +205
   System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer) +43
   System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +74
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
   System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +234
   System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +53
   System.Web.UI.Control.Render(HtmlTextWriter writer) +31
   System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +74
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
   System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +234
   System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +53
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren (HtmlTextWriter writer) +98
   System.Web.UI.HtmlControls.HtmlContainerControl.Re nder(HtmlTextWriter writer) +43
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTex tWriter output) +336
   System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +74
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
   System.Web.UI.HtmlControls.HtmlForm.RenderControl( HtmlTextWriter writer) +56
   System.Web.UI.Control.RenderChildrenInternal(HtmlT extWriter writer, ICollection children) +234
   System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +53
   System.Web.UI.Control.Render(HtmlTextWriter writer) +31
   System.Web.UI.Page.Render(HtmlTextWriter writer) +39
   System.Web.UI.Control.RenderControlInternal(HtmlTe xtWriter writer, ControlAdapter adapter) +74
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +291
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +49
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5543




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
  #2 (permalink)  
Old November 6th, 2006, 06:17 PM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

Ron:

"We have three mechanisms to off the visitor multiple selections: a CheckBoxList control, or a ListBox or DropDownList control with the SelectMode property set to Multiple." This is take from my Beginning ASP.NET Databases Using VB.NET , page 115. Page 116 further states examples and displaying and populating the multiple selection controls. Check the SelectMode property.....

And the examples work perfectly.

Hope this helps.
  #3 (permalink)  
Old November 7th, 2006, 02:04 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Ron

Can you let us know the exact scenario where you are facing this problem, are you trying to set the index (i.e. make a particular item selected) of a dropdown when you face this problem????

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
  #4 (permalink)  
Old November 7th, 2006, 09:51 AM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Thanks for your responses.

The scenario: there are multiple dropdown lists on the page. None are bound to database tables, so the likelihood of a database being part of the problem seems unlikely. Nor are any of these controls supposed to be multiple selection and making them so would not address the problem. The default value is being set by code when the page is first displayed and the user can change the value afterward, but this is happening before the user even sees the page. Moreover, the dropdowns I suspect are part of the problem are contained on hidden user controls, and one is actually buried two levels deep, making tracing the problem a little more challenging.

The circumstances: this occurs when the user clicks a checkbox on the form that is supposed to then display the hidden user controls containing the drop down lists. The postback code does not populate and/or set the selected value of the controls being shown in any way that I can see. I've put breakpoints on all code that does set the values of the drop down lists and none is executed on post back. But, if I comment out the line of code that makes the controls visible, the error no longer occurs.

My theory: it's almost like the error is occuring prior to the control being shown, but because the control is not being posted while hidden, it's not being validated. It's only when it's shown that the error is detected and thrown.

My present course of action: I'm tracing backwards to check the values when any of the dropdowns are being set to figure out which one is involved. I know there's some bizarre circumstance where VB tries to set the selected value without automatically changing the selected index that leads to its confusion of which one is really selected, but can't remember exactly what it was or I could probably have squashed this already.

Editorial note: I had naively hoped there might actually be something helpful in the error message when it said "Information regarding the origin and location of the exception can be identified using the exception stack trace below". You know, you used to be able to actually use core dumps to solve problems. But I don't see anything even remotely helpful in this stack trace and was just hopeful somebody wiser than I might know some way to make use of it to get there more quickly than the trace backwards method.

Thanks again!
  #5 (permalink)  
Old November 7th, 2006, 10:03 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well where is the code written to set the index of the dropdown initially, is it on the page or usercontrol, what I could get from the scenario is that you have already set the index of the dropdown, and when the usercontrols loads (when visible), it tries to set the index again, can u explain the visiblity and setting of dropdown index a bit more, does the page submit when the usercontrol becomes visible..........

Alternatively, just try to set the selected index false first, and then set the index of the dropdown, e.g. as below

DropDownList1.Items[DropDownList1.SelectedIndex].Selected = false;
DropDownList1.SelectedIndex = 1;

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
  #6 (permalink)  
Old November 7th, 2006, 10:46 AM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Code in the User Control sets the selected value when the control is initialized by explicit function call from the containing page. The code to do this on the parent page is within an "is not postback", and is consequently only executed once. There is no automated code for the control other than whatever .NET needs to display it.

So, when the page is displayed, all values for all controls are filled in, but only some are visible. When the user wants to change the setting for a particular control, they click a check box which reveals the setting in the context of the control. At that point, they may choose to change the setting, or perhaps they just wanted to look at it. Likewise, they may choose to save a change or not, but that is not predicated on whether they have changed the value in this specific control or whether it is currently visible or not.

Since my last post, I verified the theory that the problem is being found only when the control is displayed. I defined the control to be visible when the page is first displayed and now the error occurs immediately rather than when the checkbox is clicked. So it appears as though code running during post back was not the issue since it clearly did not run through the post back code. But the difficulty debugging this has been complicated by the unexpected revelation that hidden controls are NOT validated by whatever is throwing this error (whether it's some post generation HTML parser in .NET or the browser). Perhaps there's some logical reason why hidden .NET controls aren't validated, but it makes no more sense to me than the curious behavior of a drop down list that would throw this error rather than automatically deselecting the previously selected value and avoiding the error altogether.
  #7 (permalink)  
Old November 7th, 2006, 12:26 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

I have a little more information on the controls in question, although I'm not sure whether it's related to the problem I'm experiencing or something else. I have noticed that the second level user control (a dropdown list inside a user control that is embedded in yet another control) is being reset when the form returns from postback. AS with the first level control, there is not autoamtically executing code int it - it is populated via an explicit function call from the containing user control.
  #8 (permalink)  
Old November 7th, 2006, 02:03 PM
Friend of Wrox
Points: 793, Level: 10
Points: 793, Level: 10 Points: 793, Level: 10 Points: 793, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: OKC, OK, USA.
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

Would it be possible to move the initialization of the user controls or those statements that most occur prior to the displaying the DropDownList to the Sub Page_Init event procedure?

Just a thought.... (Whatever happened to "keeping things simple"?
  #9 (permalink)  
Old November 7th, 2006, 02:12 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

O.o This reminds me of a Jagged Array. In any case, the stack trace is EXTREMELY helpful but given your scenario, you can not ask it to be any more specific because of what you are doing, namely controls inside of controls. In any case, IMHO, this thread is being over-thought.

In VB/C# a dropdownlist, unless otherwise specified, the selectedIndex is 0. I am curious though as it sounds as you might be doing something similar to this:

drp.selectedIndex = n
drp.selectedValue = v

Where n may be 2 and v may reference position 1.

hth

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #10 (permalink)  
Old November 7th, 2006, 02:13 PM
Friend of Wrox
Points: 2,876, Level: 22
Points: 2,876, Level: 22 Points: 2,876, Level: 22 Points: 2,876, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Thanks for trying to help. The code to initialize the suspected problem control is in an explicit call made the first time the containing page is loaded. There is no automatic initialization involved currently and therefore nothing I can see to move into the initialization.

That assumes I have identified the control with the problem, of course, and I'm still not entirely certain of that yet. But I am having this weird problem with this one control where it will not retain its selected value, and that control is the one embeddeed in the other one that's having this problem. Another user control has no such problem, so I'm trying to figure out the difference between the controls that would cause one to hold its value on post back where the other does not. I'm hoping that may identify the cause of this problem, too, but lacking more information I'm kind of shooting in the dark so far.




Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList, DataSource and Selected Items kingroon ASP.NET 2.0 Basics 2 February 25th, 2008 10:41 AM
Number of selected items in a listbox sarah lee ASP.NET 2.0 Basics 2 May 17th, 2007 12:20 PM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 2.0 Basics 2 May 18th, 2006 04:59 AM
selected items in asp:ListBox jtyson Classic ASP Basics 2 July 2nd, 2004 12:01 AM
Iterating thru all child items of selected parent mahesh_ys@indiatimes.com Beginning VB 6 0 May 3rd, 2004 02:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.