asp.netcontentplaceholder

Set ContentPlaceHolder data through code ASP.NET


Is it possible to set the data in a ContentPlaceHolder through code? This is what I am thinking of:

dim oCPH as new ContentPlaceHolder
oCPH.id = "column1" 'this id is the one that corresponds with the ID I set on the page
oCPH.content = "content here" '<-- not real code

Obviously that is not correct syntax, I hope that this clarifies what I am asking.


Solution

  • You should be able to reference it through the MasterPage element on the current page. Something like:

    ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl("column1");
    

    If in the MasterPage codebehind, just reference it by name.