473,386 Members | 1,621 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,386 software developers and data experts.

Problems getting values from nested controls

Okay I have a parent page, we'll call it parent.aspx and it holds the
following two user controls

<uc1:Box1 id="Box1" runat="server"></uc1:Box1<----THIS CONTAINS A
DROP DOWN LIST
<br>
<uc1:Box2 id="Box2" runat="server"></uc1:Box2<----THIS CONTAINS A
DATALIST

In Box1, I have a dropdown list that gets selected and should set
parameters for a datalist in Box2. My question is, how can I get Box2
to read the selected item of the DropDown list in Box1.

Any help/code samples would certainly be gratefully received.

Regards
Mark

Oct 10 '06 #1
1 1645
The user controls should be completely seperate in a logical fashion. If
it's required to share data then you need to make use of what is containing
them, in this case, the page. You can expose any of your ojects that are
within a user control as properties of the control. What you'll need to do
is expose the list boxes on both controls as properties.

for example:

public DropDownList MyList
{
get{
return this.MyDropDownList;
}
}
(you may have to check this syntactically as I'm running off the top of my
head here).

Now in the parent container you could access the dropdownlist as Box1.myList
so to get the selected value property you would use
Box1.myList.SelectedValue. If you need to set values on the list you'll also
have to assign the set operation for the property as well. like so:

set
{
this.MyDropDownList = value;
}

The biggest difficulty will be if you want to attach something to the event
when the item in one of the dropdownlists is selected. You'll need to do
something called event bubbling so you can pass the selecteditemchanged
event up to the parent page. Event bubbling is a common topic, but takes a
bit more than you can get in the ng to understand. You should find some good
examples in the dotnet quickstart samples or you can search google on c#
event bubbling.

Then, you can use the values collected from control a and do whatever you
need to do to the dropdownlist in control b, such as populate it, select a
particular value, etc.. You'll have to adjust the event order that you do
things in, such as using the prerender event to do certain tasks in the
control since it fires at a time that makes it easier to get/receive
information with the parent page.

You may want to verify though if you really, really need the two seperate
controls. I say this only because a lot of programmers make this mistake of
encapsulating items that aren't really functioanally isolated and spend way
more time trying to get the two components to talk.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Roffers" <mr*****@hotmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
Okay I have a parent page, we'll call it parent.aspx and it holds the
following two user controls

<uc1:Box1 id="Box1" runat="server"></uc1:Box1<----THIS CONTAINS A
DROP DOWN LIST
<br>
<uc1:Box2 id="Box2" runat="server"></uc1:Box2<----THIS CONTAINS A
DATALIST

In Box1, I have a dropdown list that gets selected and should set
parameters for a datalist in Box2. My question is, how can I get Box2
to read the selected item of the DropDown list in Box1.

Any help/code samples would certainly be gratefully received.

Regards
Mark

Oct 10 '06 #2

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

Similar topics

19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
1
by: Marco Martin | last post by:
Hi, I have a control that nests other controls. I need to be able to get a handle on these controls when clicked. the problem is that when I click on one of the nested controls, my mouse down...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
4
by: krzysiek | last post by:
hello, i have several radiolists and checkboxlist that are generated dinamicly based on datasource. So frankly speaking i don't know names and number of that web controls cose they are always...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
2
by: Kiran Kumar Pinjala | last post by:
Hi, May be this is silly, or I just need a second pair eyes to look at this. I am trying to get values that I have edited in a datagrid and update the values with those values. Here is the code...
5
by: WesIdell | last post by:
Hi All: I need some advice regarding a problem that I'm experiencing. I'm using a group of TextBox controls in the .aspx page and am using a function in the .cs code to perform some actions with...
6
by: Yehia A.Salam | last post by:
Hello, I'm trying to create my own control derived from ScrollableControl public partial class qViewer : ScrollableControl{ public qViewer() { VScroll = true; AutoScroll = true; } ... }
9
by: wanyok | last post by:
I thought I had it figured out but I'm still getting errors :( I would appreciate any help I could get. I have two forms: Form1 and frmVerify. Once the info gets submitted on Form1 its text...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...

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.