0

データを保存した後にページを閉じる必要がある「保存して閉じる」ボタンがあります。私は多くの方法を試しましたが、どれもうまくいきませんでした。

分離コード:

protected void btnSaveClose_Click(object sender, EventArgs e)
{
    Save();
    ClientScript.RegisterClientScriptBlock(Page.GetType(), "script", "window.close();", true);
}

窓を閉めるのに助けが必要です。

4

5 に答える 5

2

メソッドに関するMDN ドキュメントでは、closeいくつかの制限について説明しています。

このメソッドは、メソッドを使用するスクリプトによって開かれたウィンドウでのみ呼び出すことができますWindow.open()。ウィンドウがスクリプトによって開かれなかった場合、次のようなエラーがコンソールに表示されます。Scripts may not close windows that were not opened by script.

つまり、このメソッドは、ウィンドウがWindow.open()メソッドで開かれない限り機能しません。

于 2013-11-01T21:27:50.437 に答える
0
string display = "Your dispaly";

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);//this will dispaly the alert box


ScriptManager.RegisterStartupScript(this, this.GetType(), "Close_Window", "self.close();", true);//this will close the page on button click

これは私のために働いた

于 2014-03-22T18:02:55.683 に答える
0

皆さん、ありがとうございました。これを修正したソリューションは次のとおりです。

protected void Page_PreRender(object sender, EventArgs e)
{
    if (ViewState["closewindow"] != null)
        closewindow = (bool)ViewState["closewindow"];

    if (closewindow)
    {
        closewindow = false;
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Close_Window", "self.close();", true);
        //System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "self.close();", true);
    }
}
于 2013-11-07T20:16:06.137 に答える