Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,

I generate textbox id on 1st button, and i need get textbox text on 2nd button click.

but when i click 2nd button did not getting id, id value is null. give me solution for this

code: This Method is caaling by button 1

C#
public void GetColumn(string tablename)
       {
           string sqlcommand = "------------------ TABLE_NAME = '" + tablename + " '  ------------------";


           using (SqlCommand cmd = new SqlCommand(sqlcommand))
           {
               using (SqlDataAdapter sda = new SqlDataAdapter())
               {
                   cmd.Connection = connection;
                   sda.SelectCommand = cmd;
                   using (DataTable dt = new DataTable())
                   {
                       sda.Fill(dt);

                       if (dt.Rows.Count > 0)
                       {

                           for (int i = 0; i < dt.Rows.Count; i++)
                           {
                               TableRow rw = new TableRow();
                               TableCell cw = new TableCell();
                               TableCell cw1 = new TableCell();

                               Label NewLabel = new Label();
                               NewLabel.ID = "Label" + dt.Rows[i][0].ToString();
                               NewLabel.Text += dt.Rows[i][0].ToString();
                               cw.Text = NewLabel.Text;

                               TextBox tb = new TextBox();
                               tb.ID = dt.Rows[i][0].ToString();
                               cw1.Controls.Add(tb);
                               rw.Cells.Add(cw);
                               rw.Cells.Add(cw1);
                               Table1.Rows.Add(rw);

                           }

                           Panel1.Controls.Add(Table1);
                       }

                       connection.Close();

                   }
               }
           }
       }


Code: This is On Button 2
                 
                           for (int i = 0; i < dt.Rows.Count; i++)
                           {
                              

                         string name =dt.Rows[i][0].ToString(); // here id is present 
                         TextBox l1 = (TextBox)Panel1.FindControl(name); // l1 is null

                                   s3 += dt.Rows[i][0].ToString() + " =  9;" + l1.Text + "' and ";
                               }
                           }
                           sw1.WriteLine(s1);
                           sw1.WriteLine(s2);
                           sw1.WriteLine(s3);

                           string s4 = ".dbo." +  " (";
                           string s5 = "";
                           string s7 = "";
                           string s6 = "values (";

                          
                           sw1.Close();
                       }
                   }
               }

           }
Posted
Updated 13-Dec-15 19:40pm
v3
Comments
phil.o 10-Dec-15 2:29am    
Please show the code you have so far that is creating the textbox.
DO NOT POST CODE IN COMMENT. Better use the "Improve question" button instead.
aarif moh shaikh 10-Dec-15 2:34am    
define this textbox object (id) globally.

In Click event you get a reference to the button itself (sender argument). Should be enough to identify it.
 
Share this answer
 
Comments
Shrikesh_kale 10-Dec-15 4:30am    
how to use can u explain
VICK 18-Dec-15 5:53am    
Button btn=(Button)sender;
The above is how to get the button in click event of that button.
Hello ,

Dynamic control id will get lost after post back .So to retain the Id of textboxes you need to create dynamic textboxes at PAGE_INIT method.

Here in your scenario you have to call your method "GetColumn(string tablename)" at the page_init method then only you can fetch your textbox id at button 2 click event.

C#
private void Page_Init(Objectsender, System.EventArgs e) 
{
    GetColumn(string tablename)
}



Thanks
Hope this give some idea
 
Share this answer
 

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