views:

46

answers:

0

I have written a class library function that parses a string to a control. It takes the current page and uses page.ParseControl to parse the string as a control.

System.Web.UI.Page page = (System.Web.UI.Page) HttpContext.Current.CurrentHandler;
System.Web.UI.Control ctrl = page.ParseControl(str); 

It works fine in most scenarios except when the caller of this function is an Ajax Web Service in which case I am getting the following error: Unable to cast object of type 'HandlerWrapperWithSession' to type 'System.Web.UI.Page'. I am obviously getting this error because the CurrentHandler is not of type Page, but I need a Page object to call ParseControl.

Any ideas how I can solve this problem?