gpt4 book ai didi

c# - 从 ASP.Net 中的 ascx 页面抓取控件

转载 作者:太空狗 更新时间:2023-10-30 00:44:47 24 4
gpt4 key购买 nike

我的 search.aspx 页面中有一个 .ascx 用户控件。如何从后面的 search.aspx.cs 代码中的 .ascx 用户控件中获取控件?

keywordSearch.Value = "value"; 
// the code behind can't see the keywordSearch control

最佳答案

通常内部控件不会从模板化用户控件中公开,因为它们被声明为protected。但是,您可以在公共(public)属性中公开控件,如下所示:

public TextBox CustomerName {
get { return txt_CustomerName; }
}

编辑:如果您需要设置控件的值,那么您最好使用公开值的属性,而不是控件:

public string CustomerName {
get { return txt_CustomerName.Text; }
set { txt_CustomerName.Text = value; }
}

关于c# - 从 ASP.Net 中的 ascx 页面抓取控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7070343/

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