Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all
I had created a number of TextBoxes in runtime, I had also writen the click event for the TextBoxes, when I click on the TextBox i.e (which was created in runtime), I want to get the Text of TextBox .

Creating the TextBox depends on a database.

C#
TextBox t = new TextBox();
t.Text = dr["temp1"].ToString();
t.BackColor = Color.CadetBlue;
t.WordWrap = true;
t.Multiline = true;
t.ReadOnly = true;
t.HideSelection = true;
t.Size = new Size(610, 50);
t.Name = "temptxt";
t.Click += new System.EventHandler(t_Click);
pan.Controls.Add(t);

I had tried a lot but no use. I had also tried by keeping the CheckBox hidden, because I should not use the CheckBox at that place, but I am not able to get the Text of the clicked TextBox.
Posted
Updated 19-Aug-10 2:38am
v3

Use the following code in the Click event handler of the TextBox
C#
void t_Click(object sender, EventArgs e)
{
    TextBox t1 = (TextBox)sender;
    string str = t1.Text; 
}
 
Share this answer
 
v2
Comments
[no name] 19-Aug-10 7:58am    
Reason for my vote of 5
good one
In the Click event handler, you will have a parameter "sender" - this is the TextBox that caused the event:
TextBox t = sender as TextBox;
if (t != null)
   {
   Console.WriteLIne(t.Text);
   }
 
Share this answer
 
Comments
[no name] 19-Aug-10 7:58am    
Reason for my vote of 5
with good explination

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900