简体   繁体   中英

How to refresh a page from another page in asp.net?

How to refresh a page from another page in asp.net? I have one page called Common.aspx. Once I click some button in another page, like Company.aspx , should refresh. How can I achieve this?

If Not ClientScript.IsStartupScriptRegistered("ReloadPage") Then
    ScriptManager.RegisterStartupScript(?,Me.GetType(), "ReloadPage", "ReloadPage();", True)
End If

Here's ReloadPage function in company.aspx . I am writing this code in Common.aspx . It is possible to call? What I should write in ? portion?

You will need Company to poll the server somehow.

This can be done using Ajax and a Javascript timer.

First have Company.aspx check for a session variable on the server on the javascript timer interval events. You can do a full Postback if the variable is set to some value you've previously chosen.

Now have Common.aspx set that Session variable when you want to.

The answer depends on how those pages are related. I guess that one of them opened the other, so if common.aspx launches company.aspx then you must get a handle of the opened window (the returned object of window.open)

var companyWindow = window.open('company.aspx'...

and do

companyWindow.location.href = companyWindow.location.href

It common is launched by company then use window.opener. But this of course works only if you can control the window.open call. If you can't then you must work on the solution by kervin

for example you have two pages ie page1.aspx and page2.aspx and you want refresh page1.aspx through page2.aspx then

add this code in page2.aspx page in aspx region

function RefreshParent() { //if (window.opener != null && !window.opener.closed) { window.opener.location.href = "page1.aspx"; //self.close(); //code for page2.aspx close //} } window.onbeforeunload = RefreshParent;

and add in page2.aspx.cs page, where you want to this activity

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "RefreshParent();", true);

//its work.....

for example you have two pages ie page1.aspx and page2.aspx and you want refresh page1.aspx through page2.aspx then add this code in page2.aspx page in aspx region **

    function RefreshParent() {
        //if (window.opener != null && !window.opener.closed) {
            window.opener.location.href = "page1.aspx";
            //self.close(); //code for page2.aspx close
        //}
    }
    window.onbeforeunload = RefreshParent;

</script>

and add in page2.aspx.cs page, where you want to this activity ,means in button click or other controls event

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "RefreshParent();", true);
//its work.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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