如何在后台代码中设置和获取用户控件中的子控件的属性?
>>>1、如何在后台代码中设置和获取用户控件中的子控件的属性?
add public properties/methods in your codebehind class for your usercontrol and declare in your page class:
protected YourUserControlCodeBehindClass YourUserControlID;
..
if you don't have a codebehind class, you can always do
UserControl c = (UserControl)FindControl("YourUserControlID");
TextBox tb = (TextBox) c.FindControl("YourTextBoxIDInYourUserControl);
tb.Text = "123";
>>>2、如何在后台设置和获取用户控件本身的属性?
if you have a codebehind class for your usercontrol, you can do
protected YourUserControlCodeBehindClass YourUserControlID;
YourUserControlID.Property1 = "123";
otherwise, you have to use Reflection
add public properties/methods in your codebehind class for your usercontrol and declare in your page class:
protected YourUserControlCodeBehindClass YourUserControlID;
..
if you don't have a codebehind class, you can always do
UserControl c = (UserControl)FindControl("YourUserControlID");
TextBox tb = (TextBox) c.FindControl("YourTextBoxIDInYourUserControl);
tb.Text = "123";
>>>2、如何在后台设置和获取用户控件本身的属性?
if you have a codebehind class for your usercontrol, you can do
protected YourUserControlCodeBehindClass YourUserControlID;
YourUserControlID.Property1 = "123";
otherwise, you have to use Reflection
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步