我做了一个WEB用户控件,上面放了1个文本框,然后放在一个页面里,我页面上放了一个按钮,单击按钮如何或的WEB用户控件上文本框里的值??

解决方案 »

  1.   

    控件加个属性:
    public string test
    {
      get { return TextBox1.Text;

    }页面就可以访问了
      

  2.   

    控件加个属性:
    public string MyString
    {
      get { return TextBox1.Text;}

    在web页面中
    public class WebForm1 : System.Web.UI.Page
    {
    protected WebUserControl MyControl;
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string myvalue=MyControl.MyString;//这里是取值
    }
    }


      

  3.   

    1.建立用户控件WebUserControl.ascx,代码如下
    protected System.Web.UI.WebControls.TextBox TextBox1;private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    }
    public string test
    {
    get
    {
    return this.TextBox1.Text;
    }
    }2.把用户控件拖到页面上,然后定义,代码如下
    protected System.Web.UI.WebControls.Button Button1;
    protected Document.WebUserControl WebUserControl1;
    private void Page_Load(object sender, System.EventArgs e)
    {
    }
    private void Button1_Click(object sender, System.EventArgs e)
    {
    Response.Write(WebUserControl1.test);
    }
      

  4.   

    问题解决  thanks  jerry_yuan(jerry) 
    我前面定义  private WebUserControl MyControl;(这样就不行)
      

  5.   

    用户控件名_文本框id
    如用户控件名是usercontrol,文本框id是textbox1
    那就是usercontrol_textbox1