I'm using a asp.net web application project, and I cannot access any asp:content controls programmaticly. I'm trying to update its contentplaceholderID in code behind. Is this possible?
Thanks
I'm using a asp.net web application project, and I cannot access any asp:content controls programmaticly. I'm trying to update its contentplaceholderID in code behind. Is this possible?
Thanks
No you can't change the contentPlaceHolderId in your content page. The reason is that contentplaceholder are set in Master page and then you reference them in there to say in which contentplaceholder your content will go.
The Content controls get left behind and don’t exist in the control hierarchy. This ASP.net thread here gives a way of how you can update it another way though
Although you probably cannot change ContentPlaceHolderId of your asp:Contents, you can control the content of ContentPlaceHolders directly: access the master page from the page through its Master property and then use the FindControl function to find the ContentPlaceHolder on the master page. After that, edit its content through the Controls property.
var masterContent = Master.FindControl("largeContent") as ContentPlaceHolder;
masterContent.Controls.Add(new Literal { Text = "Hello, world!" });
You could probably use this 'hack' to add an asp:Panel control to any ContentPlaceHolder you want so this might emulate the functionality you wanted.