代码之家  ›  专栏  ›  技术社区  ›  Anders

通过代码ASP.NET设置ContentPlaceholder数据

  •  5
  • Anders  · 技术社区  · 16 年前

    是否可以通过代码在ContentPlaceholder中设置数据?我就是这么想的:

    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
    

    显然,这不是正确的语法,我希望这澄清了我的问题。

    1 回复  |  直到 11 年前
        1
  •  6
  •   tvanfosson    16 年前

    您应该能够通过当前页面上的masterpage元素引用它。类似:

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

    如果在masterpage codebehind中,只需按名称引用它。

    推荐文章