views:

48

answers:

1

I found this really cool page that allows you to hook up facebook into your site: See here

<iframe id="MyIframe" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;amp;layout=button_count&amp;amp;show_faces=true&amp;amp;width=100&amp;amp;action=recommend&amp;amp;colorscheme=light&amp;amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>

I want to be able to call this iframe in my page (I am using ASP.NET) and I want to be able to set the visibilty based on a variable and most important I want to be able to change the src of the iframe based on a string that is build up by variables to change the "www.EXAMPLE.com" to another URL based on the location of the page.

+1  A: 

Try adding the attribute runat="server". This should give you access to the tag via your codebehind, which will let you set other attributes according to your variable.:

<iframe id="MyIframe" runat="server" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;amp;layout=button_count&amp;amp;show_faces=true&amp;amp;width=100&amp;amp;action=recommend&amp;amp;colorscheme=light&amp;amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>

This will give you access to your iframe by name in code behind. You'll then be able to things by writing statements like:

MyIframe.Visible = true;

and

MyIframe.Attributes.Add("src", "http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;amp;layout=button_count&amp;amp;show_faces=true&amp;amp;width=100&amp;amp;action=recommend&amp;amp;colorscheme=light&amp;amp;height=21");
Ryan Hayes
Thanks, that does allow me to hide it, but how will I or can I change the src? It is not picking the src up....
Etienne
@Etienne: Try that line. If an attribute isn't readily available to you in Intellisense, you can add them manually with the .Attributes Collection.
Ryan Hayes