如何在asp.net中动态更改iframe的src [英] how to change src of an iframe dynamically in asp.net
问题描述
我有一个动态更改iframe的src的问题,任何帮助都可以理解..........谢谢你...
hi , i am having a problem of changing the src of a iframe dynamically any help could be appreciated ..........thank u...
推荐答案
试试这个:
为你的iframe添加runat =server
属性。
try this:
Addrunat="server"
attribute to your iframe.
<iframe id="urIframe" runat="server"></iframe>
将 runat =server
attrubute添加到您的iframe后,您就可以从代码隐藏中访问您的iframe。
现在从codebehind添加 src
属性:
Once you add runat="server"
attrubute to your iframe you can access your iframe from codebehind.
Now add src
attribute from codebehind:
urIframe.Attributes.Add("src","http://www.facebook.com");
祝你好运。
Good luck.
Page:
<form id="Form1" method="post" runat="server">
<iframe id="ifrm" runat="server"></iframe>
</form>
Codebehind:
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
((HtmlControl)(form1.FindControl("ifrm"))).Attributes["src"] = "http://www.yahoo.com";
}
HTML:
< iframe id =gameframerunat =serverwidth =1000height =500align =middlesrc =>< / iframe>
This.gameframe.Attributes(src)=game url;
OR
HTML :
<iframe id="gameframe" runat="server" width="1000" height="500" align="middle" src=""></iframe>
This.gameframe.Attributes("src") = "game url";
也试试这段代码
also try this code
HtmlControl MyFrame = (HtmlControl)this.FindControl("urIFrameName");
MyFrame.Attributes["src"] = "yourPageName.aspx";
这篇关于如何在asp.net中动态更改iframe的src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!