Saturday, June 18, 2011

Page is null at the c# class library control

Hi all.
Just caught up in the mess when I came to see : the parent page of one of my class library control was null at runtime. That means the call:
Page.ClientScript.GetWebResourceUrl([control-type],[full-resource-url]);
would fail.

I have been suggested this happens when my parent page is being rendered within an iframe. But this was not the case for now. I was just using a placeholder to dynamically add the control. So what's the solution?

Yes it came around after some googling, try this:

(Page)HttpContext.Current.Handler).ClientScript.GetWebResourceUrl([control-type],[full-resource-url]);

What's in here?

The Page that refers to the Page control containing this dynamic control is achieved through current request handler. This avoids the problem since the request was generated by the page. But mere Page or this.Page or this.Parent.Page or whatsoever might have been missed due to the hierarchy of the controls or is it due to anything else?

Hope this helps. Sweet programming!

Popular Posts

Recent Articles