1

我试图在 response.redirect 发生之前显示一个确认弹出框。当我使用下面的代码时,我从来没有收到它只是重定向的弹出窗口。知道我缺少什么吗?

Try
        Dim msg As String = "Hello!"
        Dim script As String = "alert('" & msg & "');"
        script += "window.location.href ='frmSummary.aspx'"
        'Navigate to Page 2
        'Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SCRIPT", script,true);
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "Test",       script, True)

    Catch ex As Exception

    End Try



    Response.Redirect("~/frmMain.aspx")
4

4 回答 4

2

window.location.href逻辑放入 aJavaScript confirm而不是alert调用中,如下所示:

if (confirm("Do you want to do something?")) {
    // User clicked OK, so redirect
    window.location.href = 'frmSummary.aspx';
}
于 2013-07-08T19:59:45.367 回答
2

在您当前的代码中,服务器在渲染回客户端之前重定向到 frmMain.aspx。

如果你想用 OK/Cancel 按钮向用户显示一些东西,你想要这样的东西 -

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        string script = "if(confirm('Are you sure ...?')) {window.location.href ='frmSummary.aspx'; }";
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Test", script, true);
    }
    catch (Exception ex)
    {
    }
}
于 2013-07-08T20:02:02.257 回答
1

我会冒险猜测它指向frmMain.aspx..?

您正在尝试在客户端上呈现 Javascript,但在呈现页面之前,您正在使用此行执行重定向 -Response.Redirect("~/frmMain.aspx")

尝试评论该重定向并重试。

于 2013-07-08T19:53:20.570 回答
1

您可以使用 html/css 和一点点 js 创建自己的弹出对话框。另一种方法是创建一个处理确认对话框的 js 函数... http://www.w3schools.com/js/js_popup.asp

于 2013-07-08T20:01:53.673 回答