母板页 难点---数据交换

1 页面传值到 母板页(代码在页面端)
法一、findcontrol()方法
//把文本框中的值取出来
string s = textBox1.text;
// 将取到的值送到母板页中去
MP master= this.Master as MP; // 找到套用的母板页
//在找到的母板页中通过findcontrol 找到要操作的控件
textBox text = master.findcontrol("textBao1") as textBox;
text.text = s;

法二、在母板页中写好属性;
1 在母板页中写好属性
母板页端代码:

public string TextValue
{
get{
return textBox1.Text;

}
set {
textBox1;
}}

  


页面端代码:
//把文本框中的值取出来
string s = textBox1.text;
// 将取到的值送到母板页中去
MP master= this.Master as MP; // 找到套用的母板页
master.Textvalues = s;

ListMP listmp = this.Master as ListMP;
listmp.TextValue = s;
protected override Page_Load(object senter, EventArgs e)
{
base. Onloadcomplete(e)
if(session["dd"]!=null)
{
Text.Box2.Text =session["dd"].ToString();
}
}

  


2 母板页传值到页面(代码在母板页)
方法一、利用session 传值:
母板页端代码:
string s = TextBox1.Text;
session["dd"] =s;
页面端代码(点击按钮后):

方法二 利用代理操作~

原文地址:https://www.cnblogs.com/woniu-net/p/4763802.html