asp.net Refresh base page from iframe

别来无恙 提交于 2019-12-21 20:56:06

问题


I have page with other asp.net page inside iframe.

And on button click inside iframe i need to refresh main page from server side.

How can it?


回答1:


Make use of javascript and you can easily do it

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

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



回答2:


Its explained very well in the following links:

link 1

link 2

Hope it helps.




回答3:


For some reason the javascript function shown in earlier answers did not work for me (although the function was called). 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).

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

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


来源:https://stackoverflow.com/questions/6368948/asp-net-refresh-base-page-from-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!