472,337 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 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 1574
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...
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...
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....
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...
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...
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...
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...
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() {...
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....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.