2008-11-06 175 views
0

我有一個帶有GridView的頁面,它使用Javascript啓動一個彈出窗口。用戶然後選擇一個項目,更新連接到GridView的數據並關閉彈出窗口。ASP.NET從另一個窗口刷新一個窗口

如何刷新第一個(即調用頁面),以便可以刷新Gridview中顯示的數據?

回答

1

試試這個彈出式窗口中:

<script> 
window.opener.location.reload() 
</script> 

這應該刷新打開的彈出頁面

+1

這將導致以下內容: ------------------------ --- Microsoft Internet Explorer --------------------------- 無法重新發送信息而無法刷新頁面。 單擊重試再次發送信息, 或單擊取消返回到您嘗試查看的頁面。 – 2008-11-06 21:38:40

0

如果你只需要觸發調用頁面上回發,這應該工作:

<script> 
window.parent.document.forms[0].submit(); 
</script> 

通過明確提交表單,可以避免在刷新調用頁面時出現的警告。

如果你需要在回發期間在GridView上觸發一個OnSelectedIndexChanged事件,那麼事情有點煩瑣,但你應該可以通過調用window.parent.document.__doPostBack()並使用合適的參數來完成。

0

這裏是解決方案:

Dim CloseScript As String = "<script language='javascript'>function closeWindow(){ window.opener.document.forms[0].submit();window.close();}closeWindow();</script>" 

在.NET 2.0中,您必須將其添加到網頁上面的Javascript登記:

'register with ClientScript 
    'The RegisterStartupScript method is also slightly different 
    'from ASP.NET 1.x 
    Dim s As Type = Me.[GetType]() 
    If Not ClientScript.IsClientScriptBlockRegistered(s, "CloseScript") Then 
     ClientScript.RegisterClientScriptBlock(s, "CloseScript", CloseScript) 
    End If 
0

這是否避免「頁面無法刷新」消息

window.opener.location = window.opener.location; 

(抱歉,我本來只是留在TonyB的信息發表評論,但我不有足夠的SO點,所以我不允許... :(