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

问题参考http://topic.csdn.net/u/20111129/09/887007d1-566c-4205-85bd-063ff3b50f5d.html?seed=632864658&r=76705307#r_76705307,来自论坛网友问及:

 

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

ExpandedBlockStart.gif IGetTextBoxValueable
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实现这个接口:

ExpandedBlockStart.gif View 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转为接口,因为它有实作接口:

ExpandedBlockStart.gif View 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值