Dynamic controls are not loaded in the asp.net placeholder in the postback event

Posted by balajirnaukri-12656 under ASP.NET on 4/2/2014 | Points: 10 | Views : 793 | Status : [Member] | Replies : 1
Hi I have left navigation menu

This is been placed in the asp.net placeholder

in each <li> tag i have the following

<a onclick='if (jQuery.isFunction(processSoftwareCoremetrics)) processSoftwareCoremetrics("10000000");' href="/shop/search/Cables/result.aspx?w=B&amp;pCurrent=1&amp;ctlgfilter=&amp;key=&amp;searchscope=all&amp;sr=1">Cables</a>

tthis appears well on the page load

whereas if I have postback

<li></li> only appears whereas <a onclick> menu is not appearing

Thanks and Regards
ASP.NET Devloper
Solve-IT corp


Posted by: A2H on: 4/2/2014 [Member] [MVP] Bronze | Points: 25


When using dynamic controls, you must remember that they will exist only until the next postback.ASP.NET will not re-create a dynamically added control. If you need to re-create a control multiple times, you should perform the control creation in the PageLoad event handler . This has the additional benefit of allowing you to use view state with your dynamic control. Even though view state is normally restored before the Page.Load event, if you create a control in the handler for the PageLoad event, ASP.NET will apply any view state information that it has after the PageLoad event handler ends.

All you need to reinitialize dynamic controls before or within page load event each and every time during postback. The important thing is to assign the same ID to each control. The ViewState uses the ID property of the Control objects to reinstate the values.

Please check the below link

Please mark my reply as answer if it helps to resolve your problem

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response