Control access to Page

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hello,

Can a User Control interact with HTML Controls in the calling Page
(anything with a runat="server") from the control?

So, code in the Control impacts, for instance, the visibility of an HTML
Control in the calling page?

Any links or pointers would be appreciated.

Thank you,

Joe
 
Brock said:
Every contol has access to the page via Control.Page. You can then use
FindControl or just iterate over the Control.Page.Controls collection.

Ok, I'm showing my newbie side here, but I can't seem to get this to
work. For sake of argument I've got an ID="testBody" and a RUNAT on the
BODY element.

In my control:

public HtmlGenericControl myBody;
public void Page_Load()
{
myBody = Control.Page.FindControl("testBody");
}

I also tried

public Control myBody;

I'm getting an error:

An object reference is required for the nonstatic field, method, or
property 'System.Web.UI.Control.Page'

I know I'm just not declaring something right (still getting my head
around the object model), do I have to set something to be inheriting
the page or something?

Joe
 
Back
Top