0

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.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 .

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.