cannot find the user control with it's ID

D

Davids

I have this simple user control having a Datalist with id="MyDataList" in my
page but I can't find it using the Page.FindControl() method. So I set the
trace mode on and I see it is there but since it is placed under a panel
control which automatically has the id "ctrl02" my user control is
"ctrl02$MyDataList"

Why is that?!?!
 
E

Edge

Davids said:
I have this simple user control having a Datalist with
id="MyDataList" in my page but I can't find it using the
Page.FindControl() method. So I set the trace mode on and I see it is
there but since it is placed under a panel control which
automatically has the id "ctrl02" my user control is
"ctrl02$MyDataList"

Why is that?!?!

Very simple: otherwise you would get a duplicate ID
(MyDataList) when you add your control to the page twice.
 
D

Davids

well I can't understand that since I choose the ID and so it would be my
mistake?! How the heck can I find the control with Page.Findcontrol() if
..Net suffixes my ID with some random name??
 
B

Ben Strackany

Yeah, you won't be able to find a control within another control.

Assuming you put a user control with an ID of MyUserControl in the page, you
might be able to have your page's code use
MyUserControl.FindControl("MyDataList").
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top