重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

有母版页的内容页中的PreInit事件找不到控件的问题

最近碰上一个问题,需要在内容页中的preinit 事件访问控件,但是却会报错:未将对象引用设置到对象的实例。程序如下:
 
<%@Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Page"%> 

 
    

Content

 
    

 
 

 
    protected override void OnPreInit(EventArgs e) 
    { 
                base.OnPreInit(e); 
                ContentPageLabel.Text = "Hello, World!"; 
    } 
 
在网上查了半天,终于找到了解决方法:
 
   protected override void OnPreInit(EventArgs e)
    { 
                  base.OnPreInit(e); 
        // 下面这一行很重要
        MasterPage master = this.Master;

        ContentPageLabel.Text = "Hello, World!"; 
    } 
网上说是需要先访问一下母版页,这样内容页的控件才能实例化,才能被我们访问到。

网页题目:有母版页的内容页中的PreInit事件找不到控件的问题
本文来源:http://cqcxhl.cn/article/ishscs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP