Asp.Net:将值从Page传递给UserControl

Mel*_*elt 3 asp.net user-controls

我的aspx页面上有一个文本框,我需要一个usercontrol才能看到或访问该值,我该怎么做呢.

我在aspx页面上创建了一个公共属性

public string txtBoolValue
    {
        get { return this.txtBool.Text;}
    }
Run Code Online (Sandbox Code Playgroud)

如何从我的ascx页面调用它?

谢谢

熔化

Ami*_*rma 15

而不是在页面上创建属性为什么不在用户控件上创建可由页面设置的属性.您在问题中提到的代码将在页面和用户控件之间创建紧密耦合.

  • 在控件上创建一个公共属性,并在页面代码中引用,例如myControl.myProperty ="hello"; (3认同)