Reputation: 633
I am struggling with the below from last two days.Please help me.
I have .aspx page like this
<div>
<asp:PlaceHolder ID="pchStep4Adult" runat="server"></asp:PlaceHolder/>
<asp:button runt="server" text="next" onserverclick="ProceedNext"/>
</div>
then i have .aspx.cs code like this:
here i have a dynamic text box here and i want the text in that text box. text boxes will be added dynamically and No of text boxes will change dynamically. Any no of Text boxes are created.
public partial class pages_travelersDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb= new TextBox();
tb.ID = "tb" + i;
pchStep4Adult.Controls.Add(tb);
}
}
//Here i want the text box value in a string.
protected void ProceedNext(object sender, EventArgs e)
{
//Here i want the text box value in a string.
}
Please help me. Thanks in advance.
Upvotes: 1
Views: 186
Reputation: 460118
If it's only one TextBox:
TextBox tb = (TextBox)pchStep4Adult.FindControl("tb1");
If your example was simplified and you actually have multiple TextBoxes, you could loop the PlaceHolder's ControlCollection to get all TextBoxes.
foreach (Control ctrl in pchStep4Adult.Controls){
TextBox txt = (TextBox)ctrl;
}
Upvotes: 3