Dynamic Facebook “Like” button in ASP
Posted on | April 22, 2010 | 4 Comments
Yesterday, Facebook rolled out an update which allows people to place “Like” buttons on their websites, which is then shown in their “Recent Activities” on Facebook. As an added bonus, if one of your friends also clicked the “Like” button on the page you are viewing, you will see their thumbnail on that page. It’s kind of a neat feature, although, you have to wonder what the consequences of the “Like” button actually are, in terms of advertising, and personal information sharing.
Facebook provides a “Like” button generator which will give you the code to add to any page you need. The downside of this is that the URL is hard coded into the link, as the facebook script does not pick up where the button is being pressed, so you would need to change that on each page you want the button on. In my scenario, this just wasn’t possible, as the information I wanted to share was called from 1 webpage, which calls information from a database.
Facebook provides the coding for an iFrame, and Facebooks XFBML, if you have the SDK installed on your server. I used the iFrame version.
The first problem you will encounter is that in it’s raw form, iFrame will not allow you to use variables in it’s coding. To get around that, I created a variable which stores the complete iFrame code, and then print the iFrame variable to the webpage.
My code is below, obviously this will need to be changed slightly on your site.
< %
PageLink="http://www.yourwebaddress.com/page_details.asp?ID=" & cstr(ID)
iFrameCode="<iframe src='http://www.facebook.com/plugins/like.php?href=" & PageLink & "&layout=standard&show-faces=true&width=160&action=like&font=tahoma&" &_
"colorscheme=light' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:160px; height:90px'></iframe>"
response.write(iFrameCode)
%>
Comments
4 Responses to “Dynamic Facebook “Like” button in ASP”
Leave a Reply
April 22nd, 2010 @ 10:22 pm
Hey Shawn –
I really want to ‘like’ this, but so far, I am only ‘sort of liking it’… I am pretty sure this is what I am looking for, but need a bit more in the way of explanation if you don’t mind!
How do I use this variable of yours? Can you give example of it being implemented within actual HTML as well?
Thanks!
April 23rd, 2010 @ 9:27 am
Sure, here is a very simple webpage using it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facebook ‘Like’ Test</title>
<%
PageLink="http://www.yourwebaddress.com/page_details.asp?ID=" & request("ID")
iFrameCode="<iframe src=’http://www.facebook.com/plugins/like.php?href=" & PageLink & "&layout=standard&show-faces=true&width=160&action=like&font=tahoma&" &_
"colorscheme=light’ scrolling=’no’ frameborder=’0′ allowTransparency=’true’ style=’border:none; overflow:hidden; width:160px; height:90px’></iframe>"
%>
</head>
<body>
<%
response.write(iFrameCode)
%>
</body>
</html>
This is pretty much the same, except I’m grabbing the ID variable from the URL.
If the URL was http://www.yourwebaddress.com/page_details.asp?ID=1234, request("ID") will pick up the 1234.
Here is a website where I have implemented this.
Hope this helps.
April 29th, 2010 @ 5:33 pm
How will be part of dynamic code in ASP.net
August 27th, 2010 @ 12:35 am
Hi Shawn,
It doesnt work. It keeps linking to the main page, not the dynamic one.
tks
Ignacio