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

从中的子页向母版页的<html>标记添加内容asp.net?

  •  2
  • LocustHorde  · 技术社区  · 15 年前

     xmlns:fb="http://www.facebook.com/2008/fbml"
    

    将页面的HTML部分如下所示:

    <html xmlns:fb="http://www.facebook.com/2008/fbml">
    

    但我不想把它添加到母版页,因为我只在一个子页上使用like按钮。。有什么办法让我知道吗asp.net在加载特定子页时添加此行?

    谢谢。

    3 回复  |  直到 15 年前
        1
  •  1
  •   Ender    15 年前

    <html xmlns="http://www.w3.org/1999/xhtml" <%= FBNamespace() %>>
    

    Private _fbNamespace As String = ""
    Public Property FBNameSpace() As String
        Get
            Return _fbNamespace
        End Get
        Set(ByVal value As String)
            _fbNamespace = value
        End Set
    End Property
    

    最后在子页面:

    CType(Page.Master, MasterPage).FBNameSpace = "xmlns:fb=""http://www.facebook.com/2008/fbml"""
    
        2
  •  2
  •   Kelsey    15 年前

    是的,只需执行以下操作:

    首先将公共属性添加到母版页:

    public partial class Master : System.Web.UI.MasterPage
    {
        public bool FacebookHtml;
    

    然后在你的主人的aspx上做一个内联检查:

    <html <%= FacebookHtml ? "http://www.facebook.com/2008/fbml" : "xmlns='http://www.w3.org/1999/xhtml'" %>>
    

    MasterType 以及您的内容页):

    protected void Page_Load(object sender, EventArgs e)
    {
        Master.FacebookHtml = true;
    }
    
        3
  •  1
  •   kbrimington    15 年前

    一种方法是将HTML标记变成服务器标记。

    <head id="headtag" runat="server">
    

    var headtag = Master.FindControl("headtag") as HtmlGenericControl;
    headtag.Attributes["xmlns:fb"] = "http://www.facebook.com/2008/fbml";
    

    id

    推荐文章