Home All Groups Group Topic Archive Search About
Author
1 Nov 2005 6:02 PM
Aeden Jameson
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

Author
1 Nov 2005 6:39 PM
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

--
MY ASP.Net tutorials
http://www.openmymind.net/

Show quoteHide quote
"Aeden Jameson" <AedenJame***@discussions.microsoft.com> wrote in message
news:78FDCF14-F999-4085-8EE0-C09C9E35DF16@microsoft.com...
> 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
Are all your drivers up to date? click for free checkup

Author
1 Nov 2005 6:46 PM
Spam Catcher
"=?Utf-8?B?QWVkZW4gSmFtZXNvbg==?="
<AedenJame***@discussions.microsoft.com> wrote in
Show quoteHide quote
news:78FDCF14-F999-4085-8EE0-C09C9E35DF16@microsoft.com:

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



--
Stan Kee (spamhoneypot@rogers.com)

Bookmark and Share