Visual editing of nested masterpage pages under ASP.net 2.0

Source: Internet
Author: User
Tags net visual studio
Asp.net|erp believes that everyone has used the nested masterpage feature under ASP.net 2.0, which is powerful enough to allow users to create a template page, and then easily apply to other pages. and the stencil page can also be nested, but the nested template page, we will find that there is a problem, that is, when the use of nested template page, in the Design view state, there is no way to visualize the operation, then how to solve this problem? I looked for a foreigner's blog, found a foreigner to provide a method, can be around a corner to solve the problem, the following explanation:


we can write a base class called Basepage.cs, put it in the App_Code directory, and in this class, add a name called

The
Runtimemasterpagefile property is a string type that specifies which template file to use during run time and overrides the Onpreinit


method, the code is as follows:


public class BasePage:System.Web.UI.Page


  {


private String Runtimemasterpagefile;


  


public string Runtimemasterpagefile


   {


Get


   {


return runtimemasterpagefile;


   }


Set


   {


Runtimemasterpagefile = value;


   }


   }


  


protected override void Onpreinit (EventArgs e)


   {


if (runtimemasterpagefile!= null)


   {


this. MasterPageFile = Runtimemasterpagefile;


   }


  


base. Onpreinit (e);


   }


  }


  


then we construct a template page called Mainmaster.master, which contains a header and footer information, and a
in the middle.

called MainContent's ContentPlaceHolder, and then build a page called Submaster.master, where the


masterpagefile= "~/mainmaster.master" to apply the Mainmaster template page, which places a row and two columns of tables, as follows:


<asp:content id= "foo" contentplaceholderid= "maincontent" runat= "Server" >


  


<table>


<tr>


<td width= ">
"

  


left Column in Submaster


<br/>


  


<asp:contentplaceholder id= "leftcolumn" runat= "Server" >


</asp:ContentPlaceHolder>


</td>


<td>


  


right Column in Submaster


<br/>


  


<asp:contentplaceholder id= "rightcolumn" runat= "Server" >


</asp:ContentPlaceHolder>


</td>


</tr>


  


</table>


</asp:Content>


Finally, in an ASPX page, this specifies the


<%@ Page language= "C #" masterpagefile= "runtimemasterpagefile=" Submaster.master "codefilebaseclass=" BasePage "autoeventwireup=" true "codefile=" Default.aspx.cs "inherits=" _default "title=" Untitled Page "%>


can see here, we do not set masyterpage properties, but instead specify Runtimemasterpagefile attributes as


Submaster.master, this is the template that was loaded at runtime, and the CodeFileBaseClass attribute specifies what we just wrote

The
class Basepage.cs, so that we can see the pull in this ASPX Design view state and drag the design.


note, according to Microsoft, that the next version of Visual STUDIO is required to fully support the full Design view of the stencil nesting


State of the switch Oh


I provide an example of this article download, click here to download Http://www.cnblogs.com/Files/jackyrong/Nestedsample.zip


  


Source: Jackyrong BLOG





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.