Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Finding the Parent of a Control

Reply
Thread Tools

Finding the Parent of a Control

 
 
tshad
Guest
Posts: n/a
 
      12-03-2004
If we have nested controls, how do we easily find the parent?

I know how to find Child controls - I would do something like:

************************************************** **************************************
Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
trace.warn("inside OnSelectIndesChanged")
try
InfoLabel.Visible = False
if e.CommandName = "Select" then
DataList1.SelectedIndex = e.Item.ItemIndex
end if

dim refCode as Label = e.Item.FindControl("lblRefCode")

Dim oRepeater as Repeater =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repeater)
Dim oDetail as CheckBox =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),CheckBox)
Dim oBut as ImageButton =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),ImageButton)
************************************************** *****************************************

But what if I push a button in a child control and need to get to the Parent
control? Is there an easy way to do this?

Thanks,

Tom.


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      12-03-2004
Control.Parent

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"tshad" <> wrote in message
news:...
> If we have nested controls, how do we easily find the parent?
>
> I know how to find Child controls - I would do something like:
>
>

************************************************** **************************
************
> Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
> trace.warn("inside OnSelectIndesChanged")
> try
> InfoLabel.Visible = False
> if e.CommandName = "Select" then
> DataList1.SelectedIndex = e.Item.ItemIndex
> end if
>
> dim refCode as Label = e.Item.FindControl("lblRefCode")
>
> Dim oRepeater as Repeater =
>

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
ater)
> Dim oDetail as CheckBox =
>

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
eckBox)
> Dim oBut as ImageButton =
>

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
mageButton)
>

************************************************** **************************
***************
>
> But what if I push a button in a child control and need to get to the

Parent
> control? Is there an easy way to do this?
>
> Thanks,
>
> Tom.
>
>



 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      12-03-2004
"Kevin Spencer" <> wrote in message
news:%...
> Control.Parent


How would I use that to determine the type of control if I were passed
something like:

sub something(s as object, e as DataListCommandEventArgs)

Thanks,

Tom.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
>
> "tshad" <> wrote in message
> news:...
>> If we have nested controls, how do we easily find the parent?
>>
>> I know how to find Child controls - I would do something like:
>>
>>

> ************************************************** **************************
> ************
>> Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
>> trace.warn("inside OnSelectIndesChanged")
>> try
>> InfoLabel.Visible = False
>> if e.CommandName = "Select" then
>> DataList1.SelectedIndex = e.Item.ItemIndex
>> end if
>>
>> dim refCode as Label = e.Item.FindControl("lblRefCode")
>>
>> Dim oRepeater as Repeater =
>>

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
> ater)
>> Dim oDetail as CheckBox =
>>

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
> eckBox)
>> Dim oBut as ImageButton =
>>

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
> mageButton)
>>

> ************************************************** **************************
> ***************
>>
>> But what if I push a button in a child control and need to get to the

> Parent
>> control? Is there an easy way to do this?
>>
>> Thanks,
>>
>> Tom.
>>
>>

>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-03-2004
> How would I use that to determine the type of control if I were passed
> something like:
>
> sub something(s as object, e as DataListCommandEventArgs)


Huh??? Did someone pass a sub to you? Just pass it back.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"tshad" <> wrote in message
news:#...
> "Kevin Spencer" <> wrote in message
> news:%...
> > Control.Parent

>
> How would I use that to determine the type of control if I were passed
> something like:
>
> sub something(s as object, e as DataListCommandEventArgs)
>
> Thanks,
>
> Tom.
> >
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Neither a follower
> > nor a lender be.
> >
> > "tshad" <> wrote in message
> > news:...
> >> If we have nested controls, how do we easily find the parent?
> >>
> >> I know how to find Child controls - I would do something like:
> >>
> >>

> >

************************************************** **************************
> > ************
> >> Sub OnSelectIndexChanged(sender as Object,e as

DataListCommandEventArgs)
> >> trace.warn("inside OnSelectIndesChanged")
> >> try
> >> InfoLabel.Visible = False
> >> if e.CommandName = "Select" then
> >> DataList1.SelectedIndex = e.Item.ItemIndex
> >> end if
> >>
> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
> >>
> >> Dim oRepeater as Repeater =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
> > ater)
> >> Dim oDetail as CheckBox =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
> > eckBox)
> >> Dim oBut as ImageButton =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
> > mageButton)
> >>

> >

************************************************** **************************
> > ***************
> >>
> >> But what if I push a button in a child control and need to get to the

> > Parent
> >> control? Is there an easy way to do this?
> >>
> >> Thanks,
> >>
> >> Tom.
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-03-2004
Okay, it's hard to know what you're saying. It helps to be precise in your
terminology (as well as good practice for coding).

What you described is a signature for an Event Handler. Generally, the Event
Handler is wired up to an object, so it already knows what it's dealing
with. Perhaps you should elaborate.

I can tell you this much: You can find out anything about any object using
Reflection.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"tshad" <> wrote in message
news:#...
> "Kevin Spencer" <> wrote in message
> news:%...
> > Control.Parent

>
> How would I use that to determine the type of control if I were passed
> something like:
>
> sub something(s as object, e as DataListCommandEventArgs)
>
> Thanks,
>
> Tom.
> >
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Neither a follower
> > nor a lender be.
> >
> > "tshad" <> wrote in message
> > news:...
> >> If we have nested controls, how do we easily find the parent?
> >>
> >> I know how to find Child controls - I would do something like:
> >>
> >>

> >

************************************************** **************************
> > ************
> >> Sub OnSelectIndexChanged(sender as Object,e as

DataListCommandEventArgs)
> >> trace.warn("inside OnSelectIndesChanged")
> >> try
> >> InfoLabel.Visible = False
> >> if e.CommandName = "Select" then
> >> DataList1.SelectedIndex = e.Item.ItemIndex
> >> end if
> >>
> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
> >>
> >> Dim oRepeater as Repeater =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
> > ater)
> >> Dim oDetail as CheckBox =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
> > eckBox)
> >> Dim oBut as ImageButton =
> >>

> >

CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
> > mageButton)
> >>

> >

************************************************** **************************
> > ***************
> >>
> >> But what if I push a button in a child control and need to get to the

> > Parent
> >> control? Is there an easy way to do this?
> >>
> >> Thanks,
> >>
> >> Tom.
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      12-03-2004
"Kevin Spencer" <> wrote in message
news:%23jV7$...
>> How would I use that to determine the type of control if I were passed
>> something like:
>>
>> sub something(s as object, e as DataListCommandEventArgs)

>
> Huh??? Did someone pass a sub to you? Just pass it back.


Actually, I might have this wrong. I am using an EventArgs not the
DataListCommandEventArgs (I think).

I have a Repeater object which has a bunch of asp:Labels and asp:Link
buttons. This Repeater object is part of a DataList object. I need to get
to the parent of the Repeater this control is part of.

A LinkButton might look like:

<asp:LinkButton id="Interviews" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Interviews") %>'
onClick="Interviews_Click" />

I then have a routine:
************************************************** ***********
sub Interviews_Click(src as object, args as EventArgs)

end sub
************************************************** **************

I need to get the DataList object that is the parent of the "Interviews"
control. The Interviews control has the detail information I need to get
and my repeater is a summary. I hope I am explaining this right.

Once I get the Datalist control, I can use FindControl to get the object I
am really after (a reference code, for instance).

So I have something like

<aspataList \> objects..
<asp:repeater \> objects such as the link button below
<asp:LinkButton \>

I hope that isn't too confusing (it is to me).

Thanks,

Tom.


> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
>
> "tshad" <> wrote in message
> news:#...
>> "Kevin Spencer" <> wrote in message
>> news:%...
>> > Control.Parent

>>
>> How would I use that to determine the type of control if I were passed
>> something like:
>>
>> sub something(s as object, e as DataListCommandEventArgs)
>>
>> Thanks,
>>
>> Tom.
>> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > Neither a follower
>> > nor a lender be.
>> >
>> > "tshad" <> wrote in message
>> > news:...
>> >> If we have nested controls, how do we easily find the parent?
>> >>
>> >> I know how to find Child controls - I would do something like:
>> >>
>> >>
>> >

> ************************************************** **************************
>> > ************
>> >> Sub OnSelectIndexChanged(sender as Object,e as

> DataListCommandEventArgs)
>> >> trace.warn("inside OnSelectIndesChanged")
>> >> try
>> >> InfoLabel.Visible = False
>> >> if e.CommandName = "Select" then
>> >> DataList1.SelectedIndex = e.Item.ItemIndex
>> >> end if
>> >>
>> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
>> >>
>> >> Dim oRepeater as Repeater =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
>> > ater)
>> >> Dim oDetail as CheckBox =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
>> > eckBox)
>> >> Dim oBut as ImageButton =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
>> > mageButton)
>> >>
>> >

> ************************************************** **************************
>> > ***************
>> >>
>> >> But what if I push a button in a child control and need to get to the
>> > Parent
>> >> control? Is there an easy way to do this?
>> >>
>> >> Thanks,
>> >>
>> >> Tom.
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      12-03-2004
"Kevin Spencer" <> wrote in message
news:...
> Okay, it's hard to know what you're saying. It helps to be precise in your
> terminology (as well as good practice for coding).
>
> What you described is a signature for an Event Handler. Generally, the
> Event
> Handler is wired up to an object, so it already knows what it's dealing
> with. Perhaps you should elaborate.
>
> I can tell you this much: You can find out anything about any object using
> Reflection.


I agree.

That is what I am learning. I did send a more elaborate explanation of what
I am trying to do. I hope it is a better explanation.

Thanks,

Tom.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
>
> "tshad" <> wrote in message
> news:#...
>> "Kevin Spencer" <> wrote in message
>> news:%...
>> > Control.Parent

>>
>> How would I use that to determine the type of control if I were passed
>> something like:
>>
>> sub something(s as object, e as DataListCommandEventArgs)
>>
>> Thanks,
>>
>> Tom.
>> >
>> > --
>> > HTH,
>> > Kevin Spencer
>> > .Net Developer
>> > Microsoft MVP
>> > Neither a follower
>> > nor a lender be.
>> >
>> > "tshad" <> wrote in message
>> > news:...
>> >> If we have nested controls, how do we easily find the parent?
>> >>
>> >> I know how to find Child controls - I would do something like:
>> >>
>> >>
>> >

> ************************************************** **************************
>> > ************
>> >> Sub OnSelectIndexChanged(sender as Object,e as

> DataListCommandEventArgs)
>> >> trace.warn("inside OnSelectIndesChanged")
>> >> try
>> >> InfoLabel.Visible = False
>> >> if e.CommandName = "Select" then
>> >> DataList1.SelectedIndex = e.Item.ItemIndex
>> >> end if
>> >>
>> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
>> >>
>> >> Dim oRepeater as Repeater =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
>> > ater)
>> >> Dim oDetail as CheckBox =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
>> > eckBox)
>> >> Dim oBut as ImageButton =
>> >>
>> >

> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
>> > mageButton)
>> >>
>> >

> ************************************************** **************************
>> > ***************
>> >>
>> >> But what if I push a button in a child control and need to get to the
>> > Parent
>> >> control? Is there an easy way to do this?
>> >>
>> >> Thanks,
>> >>
>> >> Tom.
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"tshad" <> wrote in message
news:O%...
> "Kevin Spencer" <> wrote in message
> news:%23jV7$...
>>> How would I use that to determine the type of control if I were passed
>>> something like:
>>>
>>> sub something(s as object, e as DataListCommandEventArgs)

>>
>> Huh??? Did someone pass a sub to you? Just pass it back.

>
> Actually, I might have this wrong. I am using an EventArgs not the
> DataListCommandEventArgs (I think).
>
> I have a Repeater object which has a bunch of asp:Labels and asp:Link
> buttons. This Repeater object is part of a DataList object. I need to
> get to the parent of the Repeater this control is part of.
>
> A LinkButton might look like:
>
> <asp:LinkButton id="Interviews" runat="server" Text='<%#
> DataBinder.Eval(Container, "DataItem.Interviews") %>'
> onClick="Interviews_Click" />
>
> I then have a routine:
> ************************************************** ***********
> sub Interviews_Click(src as object, args as EventArgs)
>
> end sub
> ************************************************** **************
>
> I need to get the DataList object that is the parent of the "Interviews"
> control. The Interviews control has the detail information I need to get
> and my repeater is a summary. I hope I am explaining this right.
>
> Once I get the Datalist control, I can use FindControl to get the object I
> am really after (a reference code, for instance).
>
> So I have something like
>
> <aspataList \> objects..
> <asp:repeater \> objects such as the link button below
> <asp:LinkButton \>
>
> I hope that isn't too confusing (it is to me).


Tom, I think I see what you're getting at, and you may be going about it the
wrong way.

First of all, when a LinkButton is clicked inside of a Repeater, DataList or
DataGrid, an ItemCommand event is raised in the Repeater, DataList or
DataGrid. The RepeaterCommandEventArgs passed to that event handler will
supply it with the CommandName and CommandArgument properties which came
from the LinkButton, and in fact, the CommandSource property will return a
reference to the LinkButton itself. You will also get the Item property,
which is a reference to the RepeaterItem this LinkButton is inside of.

Of course, the sender parameter will be a reference to the Repeater object.
If that is inside of the DataList (or, more accurately, inside of a
DataListItem), then you can get to the DataList by:

private void MyRepeater_ItemCommand(object sender, RepeaterCommandEventArgs
e)
{
Repeater rpt = (Repeater) sender;
Control rptParent = rpt.Parent;
DataList dataList = (DataList) rptParent.Parent; // I think
}


But this only solves half of your problem. The question is exactly what do
you plan to get from that DataList? It sounds like you plan to access the
data to which the list was bound, but it won't be there on a PostBack.

Is this a generic scenario, or something that just happens on a single page?

John Saunders


 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      12-03-2004
Ok. I almost have what I want. Is there a way of doing this in one
statement?

I need to go up the tree to the DataListItem. The first parent gives me a
RepeaterItem. The second gives me a Repeater and the third gives me the
DataListItem.

The code looks like:

dim theParent as Control = src.Parent
dim theParent2 as Control = theParent.Parent
dim theParent3 as Control = theParent2.Parent
dim theDataList as DataListItem
theDataList = Ctype(theParent3,DataListItem)
dim theLabel as Label = CType(theDataList.FindControl("lblJobTitle"),label )
trace.warn("theLabel = " & theLabel.text)

Is there an easier method to do this? I'd like to do the first 3 lines as
one (since in this case I know it will always take 3 to get to the item I
want).

Thanks,

Tom

"tshad" <> wrote in message
news:eW$...
> "Kevin Spencer" <> wrote in message
> news:...
>> Okay, it's hard to know what you're saying. It helps to be precise in
>> your
>> terminology (as well as good practice for coding).
>>
>> What you described is a signature for an Event Handler. Generally, the
>> Event
>> Handler is wired up to an object, so it already knows what it's dealing
>> with. Perhaps you should elaborate.
>>
>> I can tell you this much: You can find out anything about any object
>> using
>> Reflection.

>
> I agree.
>
> That is what I am learning. I did send a more elaborate explanation of
> what I am trying to do. I hope it is a better explanation.
>
> Thanks,
>
> Tom.
>>
>> --
>> HTH,
>> Kevin Spencer
>> .Net Developer
>> Microsoft MVP
>> Neither a follower
>> nor a lender be.
>>
>> "tshad" <> wrote in message
>> news:#...
>>> "Kevin Spencer" <> wrote in message
>>> news:%...
>>> > Control.Parent
>>>
>>> How would I use that to determine the type of control if I were passed
>>> something like:
>>>
>>> sub something(s as object, e as DataListCommandEventArgs)
>>>
>>> Thanks,
>>>
>>> Tom.
>>> >
>>> > --
>>> > HTH,
>>> > Kevin Spencer
>>> > .Net Developer
>>> > Microsoft MVP
>>> > Neither a follower
>>> > nor a lender be.
>>> >
>>> > "tshad" <> wrote in message
>>> > news:...
>>> >> If we have nested controls, how do we easily find the parent?
>>> >>
>>> >> I know how to find Child controls - I would do something like:
>>> >>
>>> >>
>>> >

>> ************************************************** **************************
>>> > ************
>>> >> Sub OnSelectIndexChanged(sender as Object,e as

>> DataListCommandEventArgs)
>>> >> trace.warn("inside OnSelectIndesChanged")
>>> >> try
>>> >> InfoLabel.Visible = False
>>> >> if e.CommandName = "Select" then
>>> >> DataList1.SelectedIndex = e.Item.ItemIndex
>>> >> end if
>>> >>
>>> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
>>> >>
>>> >> Dim oRepeater as Repeater =
>>> >>
>>> >

>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
>>> > ater)
>>> >> Dim oDetail as CheckBox =
>>> >>
>>> >

>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
>>> > eckBox)
>>> >> Dim oBut as ImageButton =
>>> >>
>>> >

>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
>>> > mageButton)
>>> >>
>>> >

>> ************************************************** **************************
>>> > ***************
>>> >>
>>> >> But what if I push a button in a child control and need to get to the
>>> > Parent
>>> >> control? Is there an easy way to do this?
>>> >>
>>> >> Thanks,
>>> >>
>>> >> Tom.
>>> >>
>>> >>
>>> >
>>> >
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-04-2004
How about src.Parent.Parent.Parent?

John Saunders

"tshad" <> wrote in message
news:%...
> Ok. I almost have what I want. Is there a way of doing this in one
> statement?
>
> I need to go up the tree to the DataListItem. The first parent gives me a
> RepeaterItem. The second gives me a Repeater and the third gives me the
> DataListItem.
>
> The code looks like:
>
> dim theParent as Control = src.Parent
> dim theParent2 as Control = theParent.Parent
> dim theParent3 as Control = theParent2.Parent
> dim theDataList as DataListItem
> theDataList = Ctype(theParent3,DataListItem)
> dim theLabel as Label =
> CType(theDataList.FindControl("lblJobTitle"),label )
> trace.warn("theLabel = " & theLabel.text)
>
> Is there an easier method to do this? I'd like to do the first 3 lines as
> one (since in this case I know it will always take 3 to get to the item I
> want).
>
> Thanks,
>
> Tom
>
> "tshad" <> wrote in message
> news:eW$...
>> "Kevin Spencer" <> wrote in message
>> news:...
>>> Okay, it's hard to know what you're saying. It helps to be precise in
>>> your
>>> terminology (as well as good practice for coding).
>>>
>>> What you described is a signature for an Event Handler. Generally, the
>>> Event
>>> Handler is wired up to an object, so it already knows what it's dealing
>>> with. Perhaps you should elaborate.
>>>
>>> I can tell you this much: You can find out anything about any object
>>> using
>>> Reflection.

>>
>> I agree.
>>
>> That is what I am learning. I did send a more elaborate explanation of
>> what I am trying to do. I hope it is a better explanation.
>>
>> Thanks,
>>
>> Tom.
>>>
>>> --
>>> HTH,
>>> Kevin Spencer
>>> .Net Developer
>>> Microsoft MVP
>>> Neither a follower
>>> nor a lender be.
>>>
>>> "tshad" <> wrote in message
>>> news:#...
>>>> "Kevin Spencer" <> wrote in message
>>>> news:%...
>>>> > Control.Parent
>>>>
>>>> How would I use that to determine the type of control if I were passed
>>>> something like:
>>>>
>>>> sub something(s as object, e as DataListCommandEventArgs)
>>>>
>>>> Thanks,
>>>>
>>>> Tom.
>>>> >
>>>> > --
>>>> > HTH,
>>>> > Kevin Spencer
>>>> > .Net Developer
>>>> > Microsoft MVP
>>>> > Neither a follower
>>>> > nor a lender be.
>>>> >
>>>> > "tshad" <> wrote in message
>>>> > news:...
>>>> >> If we have nested controls, how do we easily find the parent?
>>>> >>
>>>> >> I know how to find Child controls - I would do something like:
>>>> >>
>>>> >>
>>>> >
>>> ************************************************** **************************
>>>> > ************
>>>> >> Sub OnSelectIndexChanged(sender as Object,e as
>>> DataListCommandEventArgs)
>>>> >> trace.warn("inside OnSelectIndesChanged")
>>>> >> try
>>>> >> InfoLabel.Visible = False
>>>> >> if e.CommandName = "Select" then
>>>> >> DataList1.SelectedIndex = e.Item.ItemIndex
>>>> >> end if
>>>> >>
>>>> >> dim refCode as Label = e.Item.FindControl("lblRefCode")
>>>> >>
>>>> >> Dim oRepeater as Repeater =
>>>> >>
>>>> >
>>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("Repeater1"),Repe
>>>> > ater)
>>>> >> Dim oDetail as CheckBox =
>>>> >>
>>>> >
>>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DetailCheck"),Ch
>>>> > eckBox)
>>>> >> Dim oBut as ImageButton =
>>>> >>
>>>> >
>>> CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("ExpandButton"),I
>>>> > mageButton)
>>>> >>
>>>> >
>>> ************************************************** **************************
>>>> > ***************
>>>> >>
>>>> >> But what if I push a button in a child control and need to get to
>>>> >> the
>>>> > Parent
>>>> >> control? Is there an easy way to do this?
>>>> >>
>>>> >> Thanks,
>>>> >>
>>>> >> Tom.
>>>> >>
>>>> >>
>>>> >
>>>> >
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Finding parent control value in a nested datalist c# mroffey@hotmail.com ASP .Net 3 09-17-2006 02:12 PM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy ASP .Net 2 08-15-2005 03:30 PM
What does sender.Parent.Parent.Cells() reference? Frustrating... Roy ASP .Net 2 02-11-2005 09:00 PM
Finding Control in Parent Datagrid Dave ASP .Net 0 11-13-2003 02:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57