如何与通过页面的的BasePage附着在页面母版页的工作? [英] How to work with Master Page that is attached to the page via the page's basepage?

查看:116
本文介绍了如何与通过页面的的BasePage附着在页面母版页的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.Net Web应用程序,我有一个实现跨越Web应用程序的所有页面,我的网页,从这个基地页派生功能的基础上。

In my ASP.Net web application, I have a base page that implements functionality that spans all pages of the web application and my web pages derive from this base page.

由于是整个网站的一个母版页,我不希望到母版页附加在每个网页。于是我通过的BasePage的在preINIT方法连接母版页如下:

Since there is a single master page for the entire website, I don't want to attach the master page in each of the web pages. So I attached the Master page via the basepage's OnPreInit method as follows:

    protected override void OnPreInit(EventArgs e)
    {
        this.MasterPageFile = "~/Site.master";
        base.OnPreInit(e);
    }

然而,当我切换到设计视图,我得到的母版页错误;该页面有需要母版页引用的控制,但指定诺埃。更正code查看问题。

However, when I switch to Designer view, I get the "Master Page Error"; The page has controls that require a Master Page reference, but noe is specified. Correct the problem in Code View.

当我运行应用程序,网页显示正确。

When I run the application, the webpage shows up correctly.

应该怎样做,使设计人员正确地显示出来,而不必去和每个网页的显式设置母版页?

What should be done so that the designer shows up correctly without having to go and set the master page explicitly in each of the web pages?

BTW,我是在Visual Studio 2010和.NET 4.0

BTW, I am on Visual Studio 2010 and .Net 4.0

推荐答案

您是幸运的,你可以设置母版文件,在的web.config ,然后它会在设计显示没有被明确在网页上进行设置。我只是测试它。只要看看下面的线,把你的母版页文件。

You are in luck you can set the masterpage file in your web.config, and it will show in the designer without being explicitly set on the page. I just tested it out. Just look for the line below and put in your master page file.

<pages masterPageFile="~/MasterPage.master">

这篇关于如何与通过页面的的BasePage附着在页面母版页的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆