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 s开发者_如何转开发hould 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 i.e. 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 i.e. 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.....
精彩评论