如何访问的内容页面控件从母版页在asp.net [英] How to access content page controls from master page in asp.net
本文介绍了如何访问的内容页面控件从母版页在asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是很容易从内容页访问母版页控制像
it is very easy to access master page control from content page like
protected void Page_Load(object sender, EventArgs e)
{
// content page load event
DropDownList thisDropDown = this.Master.FindControl("someDropDown") as DropDownList;
userLabel.Text = thisDropDown.SelectedValue;
}
但我怎么能访问页面内容的控制从母版页。在内容页假设一个文本框,并有一个按钮是有在母版页。我想,当我会点击主页按钮,然后我要显示文本框的内容页在母版页的标签的文本。如何实现它。请帮我code样品。谢谢。
but how could i access controls of content page from master page. suppose a textbox there in content page and one button is there in master page. i want that when i will click on master page button then i want to show the text of textbox in the content page in the label of master page. how to achieve it. please help me with code sample. thanks.
推荐答案
在母版页按钮点击事件应该由访问页面内容: -
In master page button click event should access page contents by:-
protected void Button1_Click(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)ContentPlaceHolder1.FindControl("TextBox1");
if (TextBox1 != null)
{
Label1.Text = TextBox1.Text;
}
}
这篇关于如何访问的内容页面控件从母版页在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文