locked
Help with alert message RRS feed

  • Question

  • User2029284820 posted

    Hi all,

    I have this alert message:

    string sReturn = "You are Done. Thanks!";
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("alert('");
    sb.Append(sReturn);
    sb.Append("');");
    ClientScript.RegisterOnSubmitStatement(this.GetType(), "alert", sb.ToString());


    How can I listen to this alert? I want to redirect my page to another page after the user press OK.

    Thanks

    Saturday, December 14, 2013 10:30 AM

Answers

  • User-1509636757 posted

    I understand that when user press submit button; you need to show this alert and then in press of OK button; user should be redirect to other page. Please check below sample which is working fine in this scenario:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function RedirectUser() {
                alert("You are Done. Thanks!");
                window.location.replace("http://google.com");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Button runat="server" ID="Button1" Text="Test" OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>

    On server side:

        protected void Button1_Click(object sender, EventArgs e)
        {
            //--to do .. some server side code 
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "TestScript", "RedirectUser();", true);
        }

    I have just transferred your alert code to a javascript function and added window.location.href with emulate similarly like Response.Redirect. Trivial thing here is alert message should show after code get executed and then immediately pass to another page.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 14, 2013 10:55 AM

All replies

  • User724169276 posted

    check this:

    http://forums.asp.net/t/1630105.aspx

    Saturday, December 14, 2013 10:40 AM
  • User-1509636757 posted

    I understand that when user press submit button; you need to show this alert and then in press of OK button; user should be redirect to other page. Please check below sample which is working fine in this scenario:

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function RedirectUser() {
                alert("You are Done. Thanks!");
                window.location.replace("http://google.com");
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:Button runat="server" ID="Button1" Text="Test" OnClick="Button1_Click" />
            </div>
        </form>
    </body>
    </html>

    On server side:

        protected void Button1_Click(object sender, EventArgs e)
        {
            //--to do .. some server side code 
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "TestScript", "RedirectUser();", true);
        }

    I have just transferred your alert code to a javascript function and added window.location.href with emulate similarly like Response.Redirect. Trivial thing here is alert message should show after code get executed and then immediately pass to another page.

    hope it helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 14, 2013 10:55 AM