Discussion:
Access UserControl
Gabriel
2008-05-03 18:03:27 UTC
Permalink
Hello,

I created a UserControl (MyUserControl.ascx). At design time I added this
control the a page (MyPage.aspx). No problem when I execute the page I see
it.

I'd like access to some method and properties from MyPage.aspx.cd (first
form Page_load but may be others).

Could you tell me how to access the method of my UserControl ?

Regards,

===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Efran Cobisi, cobisi.com
2008-05-09 21:53:24 UTC
Permalink
Post by Gabriel
Could you tell me how to access the method of my UserControl ?
To access your user control methods from within its containing page
code, you should first make sure that the control itself has an ID
properly set; after that, ensure the methods or properties you'd like to
reach are public ones.
Given that, public members of your control should now be accessible
using its mapped istance variable, named after the ID you set previously.

[Page markup]
<custom:MyControl id="foo" runat="server" />

[User control code]
public void Bar() { // Method implementation }

[Page code]
foo.Bar();

HTH
--
Efran Cobisi
http://www.cobisi.com

===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Loading...