Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an asp.net form and some textbox generated at runtime in Page_Load method
C#
protected void Page_Load(object sender, EventArgs e)
     {
             GenerateControll();
     }

and generatecontoroll() method is
C#
  var n = (from a in db.Parameters
                             where a.fk_OrderTypeID == OrderTypeID
                             orderby a.CodeID
                             select a);
                    foreach (var coll in n)
                    {
          if (coll.fk_ParameterTypeID == 1 || coll.fk_ParameterTypeID == 6)
                        {

                           
                            Label lblKKK = new Label();
                            lblKKK.ID = "lbl" + coll.ParameterID;
                            lblKKK.CssClass = "LabelMargin";
                            lblKKK.Text = coll.ParameterTitle;

                            TextBox txtKooft = new TextBox();
                            txtKooft.ID = "txt" + coll.ParameterID;
                            txtKooft.CssClass = "inputMargin";
                            if (coll.fk_ParameterTypeID == 6)
                            {
                                txtKooft.TextMode = TextBoxMode.MultiLine;
                            }
                            
                            Session.Add(coll.ParameterID.ToString(), txtKooft);

                        
                            pnlForm.Controls.Add(lblKKK);
                            pnlForm.Controls.Add(txtKooft);

                        }
}
}


now my controls generated dynamically, i have a button in may page and in OnClick method of that button i want get the text property of textboxes .
i write below code in my page_Init method
C#
if (Session["19"] != null)
         {
             TextBox t = (TextBox)Session["19"];
             string tID = t.ID;


             string lll = t.Text;
             }


Session[19] is not null and t and tID can find correctly but t.Text is empty while some texts wrote in this Textbox
Posted
Updated 25-Dec-13 21:07pm
v2
Comments
viprat 26-Dec-13 3:37am    
what is Session["19"]?
alibabaei 26-Dec-13 3:50am    
in this part of code some item added to the session
Session.Add(coll.ParameterID.ToString(), txtKooft);

session["19"] is added here
if i want wrote the code completely i should wrote a foreach again but i knew that session["19"] is not null and it is for checking my code

1 solution

Hi,

you have to find the textbox inside the panel using findcontrol with its id.
 
Share this answer
 
Comments
alibabaei 26-Dec-13 4:25am    
find control return me null value

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