tags:

views:

44

answers:

3

I am trying to add xfbml code in one of my child page and i realize that i have to add this line:

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

to HTML section of the page like this:

<html xmlns:fb="http://www.facebook.com/2008/fbml"&gt;

But I dont want to add it to the master page because i am using like button on only ONE child page.. is there a way I can tell asp.net to add this line when that particular child page loads?

thanks.

+1  A: 

One approach could be to make your HTML tag a server tag.

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

Your child page could then execute the code:

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

The only side effect I can see in the markup is that you wind up with the extra id attribute in the rendered HTML; however, I suspect that won't harm anybody.

kbrimington
+1  A: 

On the front end, do something like this:

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

In the backend on the masterpage, make a public property:

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

And finally in the child page:

CType(Page.Master, MasterPage).FBNameSpace = "xmlns:fb=""http://www.facebook.com/2008/fbml"""
Ender
Hi, this looks good because I can add any thing in there if need be in the future.. but I dont understand why do I need to write CType? Thanks!
LocustHorde
That casts the page's master as the type of the MasterPage in the project, so that you'll be able to use that custom property. Otherwise it just treats Page.Master as the generic MasterPage type. If your MasterPage has a different class name, then replace "MasterPage" with whatever the class name is.
Ender
You can also use <%@ MasterType VirtualPath="~/main.master" %> declaration in the content page to set the type, and avoid casting I think.
Chris Mullins
@Chris Mullins - Yes, I believe that is correct.
Ender
Hi ender, thanks, I got this to work with just a little tweaking, I use c# so i was a little unsure at first, but I also have included virtual path, and casting was not necessary as Chris Mullins pointed out, so all in all, got it to working just fine, thanks a ton for the brilliant idea!
LocustHorde
+1  A: 

Yes, just do the following:

First add a public property to your master page:

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

Then put an inline check in your Master's aspx:

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

Then in your content page just set it to true (remember to include the MasterType as well in your content page):

protected void Page_Load(object sender, EventArgs e)
{
    Master.FacebookHtml = true;
}
Kelsey