简体   繁体   English

如何从asp.net中的另一个页面刷新页面?

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

How to refresh a page from another page in asp.net? 如何从asp.net中的另一个页面刷新页面? I have one page called Common.aspx. 我有一页称为Common.aspx. Once I click some button in another page, like Company.aspx , should refresh. 单击另一页中的某些按钮(如Company.aspx ,应刷新。 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 . 这是company.aspxReloadPage函数。 I am writing this code in Common.aspx . 我在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. 可以使用Ajax和Javascript计时器来完成

First have Company.aspx check for a session variable on the server on the javascript timer interval events. 首先让Company.aspx在javascript计时器间隔事件上检查服务器上的会话变量。 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. 现在,在需要时让Common.aspx设置该Session变量。

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) 我猜他们中的一个打开了另一个,所以如果common.aspx启动company.aspx,那么您必须获取打开的窗口的句柄(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. 它由公司启动,然后使用window.opener。 But this of course works only if you can control the window.open call. 但是,这当然只有在您可以控制window.open调用时才有效。 If you can't then you must work on the solution by kervin 如果不能,那么您必须研究kervin的解决方案

for example you have two pages ie page1.aspx and page2.aspx and you want refresh page1.aspx through page2.aspx then 例如,您有两个页面,即page1.aspxpage2.aspx,并且要通过page2.aspx刷新page1.aspx ,然后

add this code in page2.aspx page in aspx region 在aspx区域的page2.aspx页面中添加此代码

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

and add in page2.aspx.cs page, where you want to this activity 并在page2.aspx.cs页面中添加您要进行此活动的位置

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "RefreshParent();", true); 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 ** 例如,您有两个页面,即page1.aspxpage2.aspx,并且要通过page2.aspx刷新page1.aspx ,然后将此代码添加到aspx区域的page2.aspx页面中**

    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 并在page2.aspx.cs页面中添加您要进行此活动的位置,表示单击按钮或其他控件事件

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

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

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