gpt4 book ai didi

asp.net - 如何从asp.net中的母版页访问内容页控件

转载 作者:行者123 更新时间:2023-12-02 08:46:35 26 4
gpt4 key购买 nike

从内容页面访问母版页控件非常容易,例如

protected void Page_Load(object sender, EventArgs e)
{
// content page load event
DropDownList thisDropDown = this.Master.FindControl("someDropDown") as DropDownList;
userLabel.Text = thisDropDown.SelectedValue;
}

但是我如何从母版页访问内容页的控件。假设内容页面中有一个文本框,母版页中有一个按钮。我希望当我单击母版页按钮时,我想在母版页标签的内容页中显示文本框的文本。如何实现它。请帮我提供代码示例。谢谢。

最佳答案

在母版页按钮单击事件应通过以下方式访问页面内容:-

protected void Button1_Click(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)ContentPlaceHolder1.FindControl("TextBox1");
if (TextBox1 != null)
{
Label1.Text = TextBox1.Text;
}
}

关于asp.net - 如何从asp.net中的母版页访问内容页控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4979669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com