2011-02-10 24 views
0

私は2つのダイナミックテキストボックスを作成しました。このように...cを使用してasp.netのテキストボックスからコンテンツを取得する#

protected void Button2_Click(object sender, EventArgs e) 
    { 
     TextBox1 = new TextBox(); 
     TextBox1.ID = "TextBox1"; 
     TextBox1.Style["Position"] = "Absolute"; 
     TextBox1.Style["Top"] = "25px"; 
     TextBox1.Style["Left"] = "100px"; 

     Panel1.Controls.Add(TextBox1); 

     TextBox2 = new TextBox(); 
     TextBox2.ID = "TextBox2"; 
     TextBox2.Style["Position"] = "Absolute"; 
     TextBox2.Style["Top"] = "60px"; 
     TextBox2.Style["Left"] = "100px"; 
     Panel1.Controls.Add(TextBox2); 
     //this.TextBox1.TextChanged += new System.EventHandler(this.TextBox_TextChanged); 
     //this.TextBox2.TextChanged += new System.EventHandler(this.TextBox_TextChanged); 

      } 

now, i want to retrieve the content from the textboxes. please tell immediately how to do this . 

答えて

2

あなたはコントロールを見つけて、この例のようなテキストを取得することができます:

string s = null; 
TextBox control = FindControl("TextBox2") as TextBox; 

if(control != null) 
{ 
    // The content is here: 
    s = control.Text; 
} 

あなたはマスターページを使用していない場合は、リクエストを調べることができます。

string s = Request.Params["TextBox2"]; 

申し訳ありませんが、私は最初のコードを読むことはありません(整形されていません)。 EventHandlerでTextBoxChangedイベントを有効にしました。

関連する問題