Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Page internally stores in private '_contentTemplateCollection' hashtable. it uses ContentPlaceHolderID property as key and stores special class (that will be used to build/initialize Content tag) as a value - so to change ContentPlaceHolderID value (defined within markup) you need to modify this hashtable, remove old entry linked with old Id and add other entry with new Id - you need to change ContentPlaceHolderId before creating master page otherwise an exception will be thrown in runtime - best place to change Ids is Page 'preinit' event and if it is better to change Ids before change master page (if you will change master page at runtime)</p> <p>To change ContentPlaceHolderID of Content tag, you can use following function in Page PreInit event</p> <pre><code>public static void AssignContentToNewPlaceHoldersWithinPage(Page pPage, string pOldId, string pNewId) { if (pPage == null || string.IsNullOrEmpty(pOldId) || string.IsNullOrEmpty(pNewId)) { return; } // Try to get a reference to private hashtable using fasterflect free reflection library in codeplex (http://fasterflect.codeplex.com/) // you can replace following line with standard reflection APIs var lTmpObj = pPage.TryGetFieldValue("_contentTemplateCollection"); if (lTmpObj != null &amp;&amp; lTmpObj is Hashtable) { var _contentTemplateCollection = lTmpObj as Hashtable; if (_contentTemplateCollection.ContainsKey(pOldId) &amp;&amp; !_contentTemplateCollection.ContainsKey(pNewId)) { var lTemplate = _contentTemplateCollection[pOldId]; _contentTemplateCollection.Add(pNewId, lTemplate); _contentTemplateCollection.Remove(pOldId); } } } </code></pre> <ul> <li>function parameter are</li> <li>pPage is reference to page instance contains content tag</li> <li>pOldId is ContentPlaceHolderId property value in markup - the Id you want to change</li> <li>pNewId is the new Id you want to use</li> </ul> <p>I hope that my answer will be useful and I am sorry if my English language is not good</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload