Why I can't find control

  • Thread starter Thread starter P.L.
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top