Dynamic controls issue in asp.net [Resolved]

Posted by Programmer123 under ASP.NET on 9/23/2013 | Points: 10 | Views : 1130 | Status : [Member] | Replies : 3
I have created a dynamic controls in my asp.net page using C#. But when the page is post back, then dynamic controls are not showing on page. Can any one tell me what is issue?




Responses

Posted by: Bandi on: 9/24/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Dynamic Controls need to be created each time the page is sent to the server, so that they reappear on the page after postback. Many times people do a mistake is they put the code that creates and adds dynamic controls in the Not isPostBack condition. In this way the dynamic controls are created only first time the page is loaded since the condition is true. But when there’s a postback by some control the dynamic controls are not created since the condition is false.

So to avoid it the code for creating dynamic controls must be placed outside all conditional blocks in the page load.

Refer the following link for retaining Dynamic controls even after PostBack
http://www.aspsnippets.com/articles/dynamic-controls-made-easy-in-asp.net.aspx
Especially look into "RecreateControls ()" function
http://forums.asp.net/t/1186195.aspx
http://stackoverflow.com/questions/10434350/why-dynamically-created-user-controls-disappear-when-controls-are-not-doing-full

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/24/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Just add the below event your .aspx page.

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
generateDynamicControls();
}


You can see the below link:-

http://forums.asp.net/t/1650874.aspx?Creating+dynamic+Controls+and+reading+values

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 9/24/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi,
refer this links it might be helpful to you
http://support.microsoft.com/kb/317794
http://www.aspsnippets.com/articles/creating-dynamic-textbox-controls-in-asp.net.aspx

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response