Finding a control

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
 
K

Karl Seguin

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
 
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.


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.
 

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

Top