继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

两个母板页嵌套,在内容页获得第一个母板页数据的问题

html5零基础入门学习
关注TA
已关注
手记 246
粉丝 81
获赞 517


解决,避免使用FindControl方法,改用接口interface.

5acf07310001405b00110016.jpgIGetTextBoxValueable using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for IGetTextBoxValueable
/// </summary>
namespace Insus.NET
{
    public interface IGetTextBoxValueable
    {
        string GetTextBoxValue();
    }
}

 

在第一个MasterPage M1.master.cs实现这个接口:

5acf07310001405b00110016.jpgView Code using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class M1 : System.Web.UI.MasterPage,IGetTextBoxValueable
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

   
    public string GetTextBoxValue()
    {
        return this.txtName.Text;
    }
}

 

最后是有内容页,把第一个MasterPage的M1转为接口,因为它有实作接口:

5acf07310001405b00110016.jpgView Code using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        IGetTextBoxValueable obj = (IGetTextBoxValueable)this.Master.Master;
        this.Label1.Text = obj.GetTextBoxValue();
    }
}

 

 效果:


 

测试代码:http://download.cnblogs.com/insus/ASPDOTNET/GetMasterPageControlValue.rar

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP

相关阅读

事件接口