8

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;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&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.

2
  • Have a look at this question: stackoverflow.com/questions/3890375/… Commented Oct 15, 2010 at 18:53
  • 1
    It is still not giving me an answer on how to talk to a iframe in my code behind..... Commented Oct 15, 2010 at 18:56

1 Answer 1

24

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;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&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 manipulate 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;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&amp;height=21"); 
Sign up to request clarification or add additional context in comments.

3 Comments

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: Try that line. If an attribute isn't readily available to you in Intellisense, you can add them manually with the .Attributes Collection.
Saved me a lot of trouble! Can't believe this trick isn't more widely known.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.