两个母板页嵌套,在内容页获得第一个母板页数据的问题
解决,避免使用FindControl方法,改用接口interface.
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实现这个接口:
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转为接口,因为它有实作接口:
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
共同学习,写下你的评论
评论加载中...
作者其他优质文章