我有在服务器端工作的 iframe:
<iframe frameborder="0" runat="server" style="width: 100%; height: 700px; background-color: #bacad3;" id="I1" name="I1" src="Page.aspx"></iframe>
然后我使用这段代码动态更改内容:
protected void Button1_Click(object sender, EventArgs e)
{
I1.Attributes["src"] = "Page.aspx";
}
我想通过以下方式用ajax实现它:
- 当用户点击 iframe 的外部时,不要回发页面并更改 iframe 的 src
- 我想在 progressupdatepanel 中显示进度
我提到它我不想运行任何回发只是通过调用 iframe 外部使用 ajax 在 iframe 内加载页面例如页面中有一个按钮,它由更新面板处理并加载其他页面的内容在 iframe 里面。 有人可以帮助我吗?
最佳答案
使用 onClientClick 和 mmke 确保您返回 false 以取消回发。
window.frames["frameName"].src = "http://example.com";
//or
document.getElementById("iframeId").src = "http://example.com";
如果你使用 runat=server 你可能需要使用客户端 id
document.getElementById("<%= iframeId.ClientID %>").src = "http://example.com";
关于c# - 使用ajax在iframe中加载内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3488713/