Hi dear
first of all i think you no need to check session on Page_Int yes if you are creating session in another page then valid for same page why you are creating session.
Please look following code it's working fine.
protected void drp_SelectedIndexChanged(object sender, EventArgs e)
{
CreateTextBox();
}
private void CreateTextBox()
{
for (int i = 0; i < Convert.ToInt32(this.drp.SelectedValue); i++)
{
TextBox txtBox = new TextBox();
txtBox.ID = "Txt" + Convert.ToString(i + 1);
txtBox.Text = "TextBox" + Convert.ToString(i + 1);
this.Panel1.Controls.Add(txtBox);
}
}
protected void btn_Click(object sender, EventArgs e)
{
GetValues();
}
private void GetValues()
{
this.Panel1.Controls.Clear();
CreateTextBox();
StringBuilder objBuilder = new StringBuilder();
string Id = "";
for (int i = 0; i < Convert.ToInt32(this.drp.SelectedValue); i++)
{
Id = "Txt" + Convert.ToString(i + 1);
TextBox txtBox = ((TextBox)this.Page.FindControl(Id));
if (txtBox != null)
{
objBuilder.Append("TextBox" + Convert.ToString(i + 1) + " Value = " + txtBox.Text);
}
}
}
You will calll CreateTextBox() method again because it's dynamically adding Controls adding on PostBack they'll remove you just check this code you will get all values.
[Edit: Removed begging for vote]
Thanks Best of luck.