【问题标题】:Redirect to a page after a pop up opens弹出窗口打开后重定向到页面
【发布时间】:2015-07-31 11:34:26
【问题描述】:

我试图在条件返回为真后重定向网页,但我似乎无法让它工作。从理论上讲,这应该,不应该。我错过了什么,有可能吗!

        protected void btnVerify_Click(object sender, EventArgs e)
    {
        if (value == txtVerification.Text || txtVerification.Text == "****")
        {
            //defines a bool to tell if the popup window has been shown, this will only ever return true
            bool PopupShown = doRedirect();

            if(PopupShown)
            {
                Response.Redirect("somewebpage.aspx");
            }
        }
        else
        {
            lblVerificationFailed.Visible = true;
        }
    }


    //Opens the popup window to fire off the download and returns true
    bool doRedirect()
    {
        string url = "GetDocs.aspx";
        string s = "window.open('" + url + "', 'GetDocs', 'height=150,width=300,left=100,top=30,resizable=No,scrollbars=No,toolbar=no,menubar=no,location=no,directories=no, status=No');";
        ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
        return true;
    }

【问题讨论】:

  • 我猜 Response.Redirect 之前的所有内容都会被忽略。我建议在当前页面中将弹出逻辑添加为 JavaScript。在执行回发之前显示弹出窗口(btnVerify-Click)。

标签: javascript c# asp.net .net


【解决方案1】:

您正在尝试在服务器上做一些可以在客户端更容易完成的事情。

您正在使用服务器事件来捕捉视图上的按钮点击,启动客户端弹出窗口,然后重定向您的页面执行。

在 javascript 上尝试这样的事情:

var btnVerify = document.getElementById("btnVerify");
btnVerify.addEventListener("click", function() {
    window.open('GetDocs.aspx', 'GetDocs', 'height=150,width=300,left=100,top=30,resizable=No,scrollbars=No,toolbar=no,menubar=no,location=no,directories=no, status=No');
    window.location.href = "somewebpage.aspx";
});

【讨论】:

  • 所以在 addEventListener 中,我需要添加两个值之间的比较,如果值匹配,则应处理点击函数,否则点击函数返回一条消息,说明验证码不'不匹配。
  • 怀疑它,如果我使用 window.location.replace 而不是 window.location 它就像我想要的那样工作。非常感谢大家:)
【解决方案2】:

怀疑它,如果我使用 window.location.replace 而不是 window.location 它的工作方式与我想要的完全一样。非常感谢大家:)

【讨论】:

    猜你喜欢
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多