Wednesday, June 4, 2014

Add Master page dynamically in your ASP.NET project C#

Here in this tutorial I will show you how to bind a page with a master page dynamically in your ASP.NET project with C#.

First of all create a new project. Then add two new master pages and one web page which will be inheriting any one of those created master page.

Now in the page PreInit event of the web page write the following code.


protected void Page_PreInit(object sender, EventArgs e)
{
    this.Page.MasterPageFile = "~/Site2.master";
}

Now run the project and do your own functionality to add your master page in other events like button click or radio button checked event as per your requirement.

Download the full source code here.

0 comments:

Post a Comment

Follow by Email

Popular Posts

Pageviews