繁体   English   中英

如何从母版页访问页面控件?

[英]How to access page controls from master page?

我知道许多内容页面都会使用txtCustomerName来创建textBox控件。 如果找到了这个,我需要从会话中更新值。 在这种特殊情况下,我无法将这些控件移至母版页。

如何从母版页访问页面控件。 在页面生命周期的哪种情况下,我们应该尝试这样做?

您可以在任何想要的事件中找到它,例如在本示例中,我在“按钮单击事件”中向您展示

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM