Finding a control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If i have a control in a class like,

class MyPage : Page {
....
protected HtmlGenericControl myCtrl;
....
}

How do I go about getting a reference to that control without using the name
myCtrl? I tried to use the method FindControl('myCtrl'), but had no luck.

Cheers,
Aeden
 
if you have this control on the page, ala:
<title id="myCtrl" runat="server" />

ASP.net will automatically hook up a reference to yoru myCtrl object in the
codebehind.

Alternatively, you should be able to do it with findControl, but note that
this isn't recursive, so you might need to to
FindControl("ParentContainer").FindControl("myCtrl")

Karl
 
If i have a control in a class like,

class MyPage : Page {
....
protected HtmlGenericControl myCtrl;
....
}

How do I go about getting a reference to that control without using
the name myCtrl? I tried to use the method FindControl('myCtrl'), but
had no luck.


myCtrl is your class name NOT the control name. A simple solution would be
to give each myCtrl a fixed name when you create them.

If you want to find a control by type, you'll have to create your own
recurisve function to search the Page's control tree.
 
Back
Top