簡體   English   中英

在Asp.NET WebForms中保存后如何關閉模式窗口

[英]How to close a modal window after a save in Asp.NET WebForms

我的主頁上有一些JavaScript代碼,當單擊鏈接時會打開一個彈出窗口:

<script language="javascript">  

function OpenResidentialAddressWin(subscriberContactRelationGid, routeId, btn) {
    window.showModalDialog("SubscriberResidentialAddress.aspx" + BuildQueryStringValuesForSubscriber(subscriberContactRelationGid, routeId, returntxtReceiptDate().value), this, strWindowFeatures + ";scroll:no;dialogWidth:442px;dialogHeight:350px");
    location.href = location.href;
}

</script>

因此,以上代碼在模式窗口中打開了頁面SubscriberResidentialAddress.aspx(以及將許多變量傳遞到此頁面中)

現在,此頁面的排列方式使其可以顯示或編輯信息。 (這些在單獨的div中顯示或隱藏,取決於在窗口中剛剛按下的按鈕)。

當前,在用戶保存頁面上的信息后,它將切換到顯示模式。 相反,我想完全關閉模式窗口並重新加載主頁。

一位同事建議我在模式窗口的aspx頁面上使用文字控件,並在成功保存后將javascript寫入該控件。 因此,我將以下內容放置在SubscriberResidentialAddress.aspx頁的頭部:

<asp:Literal runat="server" ID="litCloseWind"></asp:Literal>

然后在執行保存時調用的函數后面的代碼中

  protected void btnAddSave_Click(object sender, EventArgs e)
{

////// code related to saving

 if (status.IsSuccessful)
            {
                litCloseWind.Text = "<script>this.close()</script>";
                Response.Redirect(Request.Url.AbsoluteUri, false);
            }


}

我已經嘗試了上述方法,而且litCloseWind.Text =“ window.close()”; 但是執行保存后,沒有一個成功關閉模態窗口。

這個計划在邏輯上是否合理,我只是在某個地方犯了錯誤,還是從一開始就做錯了?

您為什么不在這里注冊腳本,像這樣:

ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");

無需在此處放置任何文字控制。

因此,您的代碼將如下所示:

protected void btnAddSave_Click(object sender, EventArgs e)
{
    if (status.IsSuccessful)
    {
        ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM