Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm changing the values of dynamic controls, but not able to get those values after static button click event

I'm binding dynamic controls on page load here it is
page load()
{
   int id = 1;
                    //get field names
                    cmd = new SqlCommand("GetDynamicFields", con);
                    con.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@DeviationID", SqlDbType.Int);
                    cmd.Parameters["@DeviationID"].Value = id;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    dt = ds.Tables[0];
                    //get field values
                    cmd = new SqlCommand("GetDatafromXML", con);

                    cmd.CommandType = CommandType.StoredProcedure;
                    //xml
                    XmlReader reader = cmd.ExecuteXmlReader();
                    con.Close();

                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    XmlElement rootElem = doc.DocumentElement;
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < rootElem.ChildNodes.Count; i++)
                        {
                            string typedata = dt.Rows[i][1].ToString();
                            switch (typedata)
                            {
                                case "int":
                                case "string":
                                    TextBox tx1 = new TextBox();
                                    tx1.ID = dt.Rows[i][0].ToString();
                                       tx1.Text = rootElem.ChildNodes[i].InnerText;
                                    td.Controls.Add(tx1);
                                    tr.Controls.Add(td);
                                    dynamictable.Controls.Add(tr);
                                    Cache["tt"] = tr;
                                    break;
                                case "combo":

                                    string hh = rootElem.ChildNodes[i].InnerText;
                                    Ddl.Items.Add(hh);
                                    td.Controls.Add(Ddl);
                                    tr.Controls.Add(td);
                                    dynamictable.Controls.Add(tr);
                                    Cache["tt"] = tr;
                                    break;
                            }
                        }
                    }
}

And I tried using cache to get changed values of dynamic controls but it showing me previous values.because its in page load event i hope.

So how do i get the change values of dynamic controls.
Posted
Updated 7-May-14 4:05am
v2
Comments
Telstra 7-May-14 7:59am    
your first line on page_load event always should be
if(!ispostback).
then debug the code and try to find on which line the problem is?
Usha Sanjee 8-May-14 1:00am    
sry i forgot to keep it. and thanks i got the solution for this

See my previous discussed article about dyanamic control use in asp.net
how to create dynamic html table and textbox in asp.net[^]
 
Share this answer
 
we can get the dynamic controls change text by using this

C#
foreach (Control ctr in dynamic.Controls)
              {

                  if (ctr is TextBox)
                  {
                      string IDs = ((TextBox)ctr).ID;
                      string values = ((TextBox)ctr).Text;
                      string text= values;
                      ele = (new XElement(IDs, values));

}
 
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