views:

437

answers:

2

Hi,

I created a control that uses an ITemplate internally in order to allow the user to add its own stuff.

<my:MyControl id="myControl" runat="server">
   <Content>
         //some stuff in here
   </Content>
</my:MyControl>

The "Content" property is the template. (This is just simplified. This construct is within a larger control).

Now I'm having the problem that my user places his own UserControl within the <Content>..</Content>. That shouldn't be a problem, but the UserControl makes a call to the QueryString of the page in the PageLoad event. And now I recognized that the Page object is null when the UserControl resides within the template while it works if it is placed outside, just normally on the page.

Does anyone have an idea what could be the problem here?

+1  A: 

I have seen a case where this.Page returned null from within a nested user control.

In that case using the construct "(Page)HttpContext.Current.Handler" to get the page object worked fine.

Hope that helps,

Jim

Jim
Thx for your post. The problem is just that the call to the page object is done in one of the user controls which some developer using my control may have written. So I have no control over that...
Juri
A: 

I don't know if it's of any use anymore, but maybe it still of some use...

When you instantiate the template (with InstantiateIn), is the resulting control hierarchy actually added to your MyControl's Controls collection? AFAIK, that's the way to ensure you've got a non-null Page property.

Ruben