开发者

getting the content from textbox in asp.net using c#

I have created two dynamic textboxes. like this...

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.A开发者_Go百科dd(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 .


You can find control and get text like in this example:

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

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

If you're not using a MasterPage, you can interrogate the request:

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

Sorry, i've no read the first code (is not well formatted). You have valorized TextBoxChanged event, in the EventHandler you can use "sender":

TextBox control = sender as TextBox;
string s = null;
if(control != null)
   s = control.Text;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜