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 : 1707 | 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

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

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp



Responses

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

Up
0
Down
Hi,

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
http://www.codeproject.com/Articles/3684/Retaining-State-for-Dynamically-Created-Controls-i
http://www.dotnetbull.com/2013/09/maintain-dynamic-control-events-data-during-postback.html

Thanks,
A2H
My Blog

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

Login to post response