Search This Blog

Sunday, 29 May 2011

Dynamic Compilation of ASP.Net page using BuildManager Class

Few days back I came across a problem on asp.net site where a user wanted to get information about controls of a Page from a different page. Problem with this approach is that server loads the requested page in memory. So at one time you can be only in one page say Page1. We can create object of Page2 from Page1 but can't get information about controls since controls gets initialized only when Page_Init fires and since we are just creating object of Page there is no life cycle involved with this.

Now just to get you started .Net provides lot of classes that help in dynamic compilation of pages and can be very useful if you want to cache your pages for faster access and better user experience. You should know that asp.net pages are compiled when requested by user and cached for later use.

The class that we are going to discuss and use is BuildManager class.Lets count number of panel controls in Page2 from Page1.

I wrote an article on asp.net wiki site long time back explaining the approach...

Please refer original article for complete sample and understanding..

http://wiki.asp.net/page.aspx/894/get-information-of-programatically-created-aspnet-page-using-buildmanager-class/

1 comment:

  1. Very nice.
    Always want to do that but nobody knows how.

    ReplyDelete