Friday, June 20, 2008

Access The Page Object From a Separate Class in ASP.NET

I just found this out today and thought you might want it for your notes. For awhile now I've been under the impression that the Page object was inaccessible from a class outside of the codebehind page. Today I found out that I was wrong. To access the Page object you simply need to do the following:

Page page = (Page)HttpContext.Current.Handler;
It would have been alot nicer if they included a property of HttpContext that would work like this: HttpContext.Current.Page, but for some stupid reason they did not do that. Anyway, I know that I was happy to find that out so I thought you might want to know too.

No comments: