Why I can't find control

P

P.L.

Hi!

I have problem with Datarepeater control. When I load template from external
aspx file

ItemTemplate = Page.LoadTemplate(....);

I can't find control in ItemDataBound event.

((Label)e.Item.FindControl("Label1")).Text = "text";

Can someone help me?

Petr
 
P

Patrice Scribe

Can you find this control in the hierarchy (enable the trace ?)

I's perhaps because you should find starting with the naming container that
contains this Label1 control ?

(Label)a.Item.FindControl("SomeINamingContainer").FindControl("Label1").Text
etc...

Patrice
 
P

P.L.

Yes, when I use

(Label)a.Item.Controls[0].FindControl("Label1").Text

it works! How can I write code accepted both ItemTemplates - in repeater
code or loaded from template file?

Thanks

Petr
 
P

Patrice Scribe

IMO it should work in both cases (does it ?)

I would say that the "first" control (usually a TR tag) "carries" the
"naming container" functionnality so that each row can have its own "Label1"
control....

I'm working on simialr things and for now never hard to deal with this (but
I'm using always RepeaterItem.Controls(0).FindControl("Name"))

Patrice


--

P.L. said:
Yes, when I use

(Label)a.Item.Controls[0].FindControl("Label1").Text

it works! How can I write code accepted both ItemTemplates - in repeater
code or loaded from template file?

Thanks

Petr


Patrice Scribe said:
Can you find this control in the hierarchy (enable the trace ?)

I's perhaps because you should find starting with the naming container that
contains this Label1 control ?
(Label)a.Item.FindControl("SomeINamingContainer").FindControl("Label1").Text
etc...

Patrice
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top