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
 
Old November 7th, 2006, 02:14 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

It feels very much like this, but I'll be darned if I can figure out where such code lies in the program.
 
Old November 7th, 2006, 02:17 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

In so far as the ddl not retaining its selected index, it sounds like (somewhere) something is getting reintialized and clearing the value you are setting. That is why I am a big fan of static Members and Properties since they do not require an instance of the object to set or get those values AND you dont have to worry about their values being reset when the object is initialized.

-------------------------
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
 
Old November 7th, 2006, 02:23 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 know it seems like it, but breakpoints in the user control initialization process are not being hit. It fires an event to its container when a value is selected by the user, and that's it. I'll try it again, but I'd swear it's not doing anything in the control code that would reset the value.

I wonder whether the page is perhaps not maintaining the state of this control so it is losing its selected value on post back. Isn't there a setting someplace to tell it to do so and maybe that also needs to be applied to user controls, too?
 
Old November 7th, 2006, 03:11 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

No I think not. I have a user control that generates a series of dropdown boxes based on X input (These are runtime created dropdownlists) they ALWAYS have 3 values, however, the selectedItem differs based on data in a database.

It is a worthwhile note that all of the dropdowns AutoPostBack when their values are changed and I have never had an issue with values being reintialized and such and the page parameters are the VS Default. How do you access the value that determines the selectedValue? A public variable or a property?

-------------------------
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
 
Old November 7th, 2006, 03:18 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

The value is references as a user control property, not as a public control or variable. But it's never getting that far because the value is lost on the post back, before the code that saves the selected value ever runs.
 
Old November 7th, 2006, 03:32 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

Ok.

The checkbox is obviously raising an event in which you are unhiding a UserControl. At this step, your control has already been initialized in an "Not Page.IsPostBack" section of code, correct?

The line of code you comment out, what is it? A call to a method in the UserControl, a Property, or??

What exactly happens when you make that call to the usercontrol (e.g. program flow)?

Does the above mentioned UserControl then reference ANOTHER UserControl?

The checkbox, is it in a seperate user control or is it contained on the Page that contains the hidden usercontrols?


-------------------------
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
 
Old November 7th, 2006, 05:24 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

Yes, the control should already be initialized AND the default value should already have been selected before the control is made visible. The checkbox is a simple postback control with code in the clicked event.

The line of code, which when commented out no longer renders the error, is:

usercontrol.visible = true

This is actually in a sub outside the check box click event, and it manipulates a lot of other controls on the same form, but the line above is the one that seems to make the error appear (as opposed to actually causing the error). This is why I think the error occurs before this line - that code clearly has nothing to do with selecting values from a drop down list.

The user control made visible only references the user control where I suspect the problem is occurring. That user control is embedded in the first user control in the same way the first user control is embedded in the page. So flow would be - page calls UC1 which then calls UC2, although what is being "called" is questionable if all it's doing is making the control visible and there's nothing in the Init method for either user control.

The checkbox is a standard ASP control on the same page as the user control, and just above it.
 
Old November 7th, 2006, 05:44 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Ron,

You probably need to call ClearSelection before you set the selected item. I ran into this issue too some time ago, but I can't recall the exact situation where and how it occurred.

Somehow, the error doesn't occur when you set the SelectedIndex directly, but when you use FindByValue to select the item.

myList.Items.FindByValue("SomeValue").Selected = true;

may cause the error, even though no other value has been set explicitly. Calling ClearSelection fixed it for us:

myList.ClearSelection();
myList.Items.FindByValue("SomeValue").Selected = true;

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 8th, 2006, 10:21 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

I still don't know which drop down was the problem child, but I dropped that magic bullet before each attempt to set the selected item for every drop down list on the form, and voila, no more multiple selection error. Now if I can just remember that solution when I code my next page. Thanks, Imar!

I still haven't figured out why the drop down in the one user control is not retaining its value on postback, though. Any pearls of wisdom for me on that one, o' wise one? ;)
 
Old November 8th, 2006, 10:50 AM
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

Unfortunately, that is so related to program flow and how your page interacts with the different user controls that, I don't think, any of us could give you an accurate answer on that without looking over your entire source code. (We could speculate all day, however)

-------------------------
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




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.