FacebookApplication Without User Control

Jan 21, 2008 at 7:11 AM
I want to use a base page to manage creating the FacebookApplication user control instead putting the code to create a user control on every page like so.

<fb:FacebookApplication ID="fbApplication" runat="server" Mode="IFrame"
EnableExternalBrowsing="false"
ApplicationName="helloWorld"/>


Does anybody know how it is possible (creating the FacebookApplication programatically) or if it is advisable. Thanks.

Mitch
Jan 21, 2008 at 3:18 PM
Hmm, now you've got me thinking - in general you can create a control and add it to the page's control collection programmatically. So there's not reason that you shouldn't be able to do this if you do it in the right method(s), probably OnPreInit(). But I doubt it's worth the trouble.

I've got a base page class, which has the definition for the FacebookApplication control in it. I still have to put the above tag in the .aspx file for each of my pages, but I can access the fbApplication variable from generic functions in the base class. I'm guessing this is the reason you want a base class to begin with.

Or you could probably use master pages, but for my project it wasn't worth the trouble. I can't think of a reason they would be incompatible with facebook or facebook.net.
Jan 23, 2008 at 7:15 PM

Thanks jgr4, I agree, it might not be worth the trouble, but it seems to me that it would be a much cleaner way of implementing everything. For now I have adoped your solution, putting a <fb:FacebookApplication> tag on every page and accessing it via the base class.

I have been experimenting with LoadControl() in the base page, but I can't seem to get the syntax correct (Most of the LoadControl docs demonstrate using .ascx's). If anybody out there has any advise, please let me know.

Thanks,

Mitch
Jan 23, 2008 at 8:42 PM
Edited Jan 23, 2008 at 8:43 PM
I just did a Master page with a public property representing the FacebookApplication object. Then I added a property to my base page class like so

protected FacebookApplication FacebookApp
{
get
{
return ((AppMaster)Master).FacebookApp;
}
}

It works swell.

Bill
Jan 24, 2008 at 7:31 PM
Thanks Bill. I'm going to adopt your solution.
Coordinator
Jan 29, 2008 at 7:24 AM
You can also use FacebookApplication.GetCurrent(Page) from any control or from a page/user control.