简体   繁体   English

asp.net从iframe刷新基页

[英]asp.net Refresh base page from iframe

I have page with other asp.net page inside iframe. 我在iframe中有其他asp.net页面的页面。

And on button click inside iframe i need to refresh main page from server side. 并在按钮上单击iframe我需要从服务器端刷新主页。

How can it? 怎么样?

Make use of javascript and you can easily do it 使用javascript,你可以轻松地做到这一点

call the following function on your button click 在单击按钮时调用以下功能

<script language="javascript">
function RefreshParent()
{
window.parent.location.href = window.parent.location.href;
}
</script>

From the cs code if you are opening the aspx page in the iframe 如果您在iframe中打开aspx页面,请从cs代码中获取

Page.RegisterStartupScript("RefreshParent","<script
language='javascript'>RefreshParent()</script>");

For some reason the javascript function shown in earlier answers did not work for me (although the function was called). 出于某种原因,早期答案中显示的javascript函数对我不起作用(尽管函数被调用)。 However, this worked for me: 但是,这对我有用:

    function RefreshParent()
    {
        // Was: window.parent.location.href = window.parent.location.href;
        parent.location.reload(); 
    }

I had to add it near the start of my HTML (near the end of the HTML didn't work, as it was not yet rendered). 我不得不在我的HTML开头附近添加它(接近HTML的末尾不起作用,因为它还没有渲染)。

I used this C# code to call it, which is based on earlier answers but updated to use the current API which has an extra initial paramter, "type": 我使用这个C#代码来调用它,它基于之前的答案,但更新后使用当前的API,它有一个额外的初始参数,“type”:

ClientScript.RegisterStartupScript(this.GetType(), "RefreshParent", "<script language='javascript'>RefreshParent()</script>");

Its explained very well in the following links: 它在以下链接中解释得非常好:

link 1 链接1

link 2 链接2

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM