Reputation: 17831
I'm currently learning to use MasterPages and ContentPlaceHolders in ASP.NET 3.5 and C# - and right now, I'm desperately trying to edit the contents of an asp:Content-Control through my programming code.
Background is this; As soon as a Button is pressed, I want the asp:Content to be cleared and filled with dynamic generated content through the *.cs-File.
But I can't figure out how to access the asp:Content-Control, neither through its ID or Page.FindControl etc.
So, how can you edit the contents of a asp:Content-Control through your programming code?
Upvotes: 2
Views: 1536
Reputation: 1519
You can access a ContentPlaceholder by using FindControl not on the page object, but on its master page.
System.Web.UI.MasterPage masterPage = this.Master;
ContentPlaceHolder pageContent;
pageContent = (ContentPlaceHolder)masterPage.FindControl("YourContentPlaceholderName");
I'd agree though that it's better to define a panel or placeholder within this block and access that directly, rather than try to modify the ContentPlaceholder
Upvotes: 2
Reputation:
You can put an asp:Panel into the ContentPlaceHolder and move the placeholder markup into it. This way you can get to the Panel container and manipulate its content.
Upvotes: 1
Reputation: 2869
Did you forget to add runat="server" to your asp:Content-Control?
Regards,
M.
Upvotes: 0