[英]getting the content from textbox in asp.net using c#
我創建了兩個動態文本框。 像這樣...
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 .
您可以找到控件並獲取文本,例如以下示例:
string s = null;
TextBox control = FindControl("TextBox2") as TextBox;
if( control != null )
{
// The content is here:
s = control.Text;
}
如果您沒有使用MasterPage,則可以詢問請求:
string s = Request.Params["TextBox2"];
對不起,我沒有讀過第一個代碼(格式不正確)。 您已經為TextBoxChanged事件增值,在EventHandler中您可以使用“sender”:
TextBox control = sender as TextBox;
string s = null;
if(control != null)
s = control.Text;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.