Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an aspx page, that is binding dynamic tabs from User Control Page. The code is as follows:

TabPanel tbPanel;
foreach (var personInfo in personsList)
{
tbPanel = new TabPanel();
tbPanel.ID = "TabPanel" + personInfo.PersonCode;
tbPanel.HeaderText = personInfo.FirstName + " " + personInfo.LastName;
tbPanel.ContentTemplate =
Page.LoadTemplate("~/UserControl/UCPartnershipStatementFull.ascx");
tbContainer.Tabs.Add(tbPanel);
}

Earlier, the User Control page just used to display some set of data based on backend calculations.

Now, the requirement is to add some text boxes on the User Control page, and then fetch it's value (as entered by user) and store in database, making it just like a form page.

I am having trouble fetching the textbox value from User Control page. When I do textbox.Text on the master aspx page, it gives null.

Please let me know if I can fetch the textbox value either on aspx.cs page or the User Control(ascx.cs) page? And How?

What I have tried:

Textbox added on UCPartnershipStatementFull.ascx:-


<asp:textbox runat="server" id="txtPtrTradeProfessionProfitFPS" enabled="true" cssclass="form-control" value="0.00">



On UCPartnershipStatementFull.ascx.cs page:-

protected void Page_Load(object sender, EventArgs e)
{
string a = txtPtrTradeProfessionProfitFPS.Text;
}
Posted
Comments
Richard Deeming 19-Apr-23 7:22am    
Most likely you're creating the dynamic controls at the wrong point in the page lifecycle. Ideally, this needs to be done in response to the tbContainer control's Init event. But at the absolute latest, you need to create them in the page's Init event.

But since you haven't told us when you're adding the dynamic controls, that's just a guess.
Member 10044248 19-Apr-23 7:43am    
I am adding the dynamic control on OnPreRender of the master page.

protected override void OnPreRender(EventArgs e)
{
TabPanel tbPanel;
foreach (var personInfo in personsList)
{
tbPanel = new TabPanel();
tbPanel.ID = "TabPanel" + personInfo.PersonCode;
tbPanel.HeaderText = personInfo.FirstName + " " + personInfo.LastName;
tbPanel.ContentTemplate = Page.LoadTemplate("~/UserControl/UCPartnershipStatementFull.ascx");
tbContainer.Tabs.Add(tbPanel);
}
}

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