C# 从ASP.NET代码隐藏到iFrame

C# 从ASP.NET代码隐藏到iFrame,c#,asp.net,vb.net,facebook,iframe,C#,Asp.net,Vb.net,Facebook,Iframe,我发现了一个非常酷的页面,可以让你将facebook连接到你的网站: 我希望能够在我的页面中调用这个iframe(我使用的是ASP.NET),我希望能够基于变量设置可见性,最重要的是,我希望能够基于由变量生成的字符串更改iframe的src,以更改“www.EXAMPLE.com”根据页面位置添加到另一个URL。尝试添加属性runat=“server”。这将允许您通过codebehind访问标记,这将允许您根据变量设置其他属性: <iframe id="MyIframe" runat=

我发现了一个非常酷的页面,可以让你将facebook连接到你的网站:



我希望能够在我的页面中调用这个iframe(我使用的是ASP.NET),我希望能够基于变量设置可见性,最重要的是,我希望能够基于由变量生成的字符串更改iframe的src,以更改“www.EXAMPLE.com”根据页面位置添加到另一个URL。

尝试添加属性runat=“server”。这将允许您通过codebehind访问标记,这将允许您根据变量设置其他属性:

<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>


看看这个问题:它仍然没有给我一个关于如何在我的代码中与iframe对话的答案……谢谢,这确实允许我隐藏它,但是我将如何或者我可以如何更改src?这并不是把src接起来……@Etienne:试试那句话。如果某个属性在Intellisense中不可用,您可以使用.Attributes集合手动添加它们。为我省去了很多麻烦!真不敢相信这个把戏还没有广为人知。
<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>
MyIframe.Visible = true;
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");