【问题标题】:Get Text property with asp control用asp控件获取Text属性
【发布时间】:2011-07-05 06:13:32
【问题描述】:

我使用代码创建了控件:

...Page_Load(...)
{
...
TextBox tBox = new TextBox();
tBox.ID ="SpecificID";
somePanel.Controls.Add(tBox);
...
}

如何使用此控件获取 Text 属性(如SpecificID.Text)???

【问题讨论】:

    标签: asp.net text controls properties


    【解决方案1】:
    TextBox textBox = Form.FindControl("yourid") as TextBox
    string text = textBox.Text
    

    【讨论】:

      【解决方案2】:
      TextBox textBox = somePanel.FindControl("SpecificID") as TextBox;
      string text = textBox.Text;
      

      我假设您提到的“somePanel”是您在页面中使用的 asp.net 面板控件。

      【讨论】:

        【解决方案3】:
                TextBox tBox = new TextBox();
                tBox.ID = "1";
                tBox.Text = "hi";
                form1.Controls.Add(tBox);
        
                string Text= tBox.Text;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多