页面继承 [英] Pages inheritance

查看:73
本文介绍了页面继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个课程,我必须使所有页面都从该课程继承,
我不想让每个页面都继承自一个类
有没有一种方法可以使所有页面从该类继承而来??

谢谢

hello

i have a class and i must make all pages inherite from it ,
i dont want to make each page inherite from a class
is there is a way to make all pages inherite from this class in one step ???

Thanks

推荐答案

将此保存在您的Web配置文件中

Have this in your web config file

<configuration>
  <system.Web>
    <pages masterPageFile="your master name.master" />
  </system.Web>
</configuration>





the

<system.web></system.web>

标记可能已经存在,则只需在其内部添加pages标记.不要定义新的System.Web标签

上一个适用于.Net Framework 4,某些较低版本的语法可能为

tag may be already exists, then only need to add the pages tag inside of it. Don''t define a new System.Web tag

The above one is for .Net framework 4, some of the lower version may have this syntax

<pages master="your master.master"></pages>



可以具有从从母版页继承的类继承的母版页.

如果所有页面都必须使用公共基类,或者可以使用具有Page类扩展方法的类.

例子...



Can have a master page inherited from a class inherited from master page.

In case of all the pages has to use a common base class, alternatively can have a class with extension methods for the Page class.

Example...

public static class PageExtensionMethods
{
    public static string GetDefaultCopyRightString(this Page globalPage)
    {
        return "Copy Right Reserved Test Company , 2011";
    }
}




现在,您可以在任何页面(即所有页面)中调用此方法..example..




Now you can call this method from any page i.e in all pages..example..

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       string copyRight=this.GetDefaultCopyRightString();
    }
}


这篇关于页面继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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