ok button on alert

Last post 06-11-2008 11:43 PM by sivakl_2001. 7 replies.

Sort Posts:

  • ok button on alert

    06-09-2008, 6:57 AM
    • Member
      32 point Member
    • stevedale
    • Member since 08-14-2007, 9:22 AM
    • Denmark
    • Posts 137

    Hello, I show an alert with the following code..

    string strScript2 = "<script language=JavaScript> alert('" + "bla bla...." + "')</Script>";

    ClientScript.RegisterStartupScript(typeof(Page), "key", strScript2);

    and would like to redirect to another page when the user clicks in the alert ok button - is this possible?

    Thanks,

    Steve

  • Re: ok button on alert

    06-09-2008, 7:12 AM
    Answer

    Use confirm box rather than alert

    <!--
    function confirmation() {
    var answer = confirm("Leave tizag.com?")
    if (answer){
    alert("Bye bye!")
    window.location = "http://www.google.com/";
    }
    else{
    alert("Thanks for sticking around!")
    }
    }

     

    If this post was useful to you, please mark it as answer. Thank you!

    Regards.
    mimranshafiq
    .NET Web Developer
    http://www.dotnetclassic.com
  • Re: ok button on alert

    06-09-2008, 7:29 AM
    Answer
    • All-Star
      30,502 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 5:53 PM
    • Dhaka, Bangladesh
    • Posts 3,292
    • Moderator

    If you don't wish the user an option, then you should use alert.

     

    function alertAndGo()

    {

      alert('leaving...');

      window.location = "some url";

    }

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: ok button on alert

    06-09-2008, 7:29 AM
    • All-Star
      30,502 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 5:53 PM
    • Dhaka, Bangladesh
    • Posts 3,292
    • Moderator

    Arghhh....I pushed tab and two spaces and tinyMCE made two posts. Could a mod please delete this? Thanks.

     
    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: ok button on alert

    06-09-2008, 7:37 AM
    Answer

    hi, you can try the following code

    string strScript2 = "<script language=JavaScript> alert('" + "bla bla...." + "'); document.form1.action='Default.aspx';document.form1.submit();</Script>";

    ClientScript.RegisterStartupScript(typeof(Page), "key", strScript2);

     

    Note: I had redirect to Default.aspx, u can change it

    From:
    Himanshu Hajariwala
    For More Helps Visit : http://himanshu-hajariwala.blogspot.com/
    IF IT HELPS YOU THEN KINDLY PRESS THE "ANSWER" BUTTON.
  • Re: ok button on alert

    06-09-2008, 7:58 AM
    Answer
    • Contributor
      3,091 point Contributor
    • sameer_khanjit
    • Member since 12-10-2007, 1:06 PM
    • Indore India
    • Posts 638

     I think u required Ok and cancel both button

     

    <<html>
    <head>
    <script type="text/javascript">
    <!--
    function confirmation() {
    var answer = confirm("Leave tizag.com?")
    if (answer){
    alert("Bye bye!")
    window.location = "http://www.google.com/";
    }
    else{
    alert("Thanks for sticking around!")
    }
    }
    //-->
    </script>
    </head>
    <body>
    <form>
    <input type="button" onclick="confirmation()" value="Leave Tizag.com">
    </form>
    </body>
    </html>
    We Are Looking for .NET/PHP Projects

    Contact Details :-

     Email - sameer.khanjit@gmail.com

     Mobile no. : +91-9893795983

     View Blog

    linkedin Asp.net Group

    Don't forget to click “Mark as Answer” on the post that helped you
  • Re: ok button on alert

    06-11-2008, 2:03 PM
    Answer
    • All-Star
      15,283 point All-Star
    • yasserzaid
    • Member since 09-22-2007, 9:10 PM
    • Egypt
    • Posts 2,586

    Hi

    try this

     

    1. In your button attach the following event marked in bold
    
       <asp:Button runat="server" id="btnDelete" Text="Delete" onClientClick="return Confirmation();" />
    
    Now locate the <head> tag in your aspx page (html) . Inside head tag add a javascript function named Confirmation()
    
    <head>
    
    <script>
    
    function Confirmation()
    {
    
        var ans;
    
        ans = confirm('Are you sure want to delete?');
    
        if(ans)
    
        {
    
             return true;
    
        }
    
       else
    
       {
    
            return false;
    
       }
    
    
    }
    
    </script>
    
    </head>
    
    
    //---------------------------------------
    
    cmdButton.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');");
     
    Yasser Zaid
    My Blog [http://yasserzaid.wordpress.com/]
  • Re: ok button on alert

    06-11-2008, 11:43 PM
    Answer
    • Contributor
      2,778 point Contributor
    • sivakl_2001
    • Member since 01-11-2008, 3:13 AM
    • Kuala Lumpur, Phileo Damansara
    • Posts 804

    hi friend try like this

    string strScript2 = " alert('Redirect to.. '); window.location=Home.aspx; "; 

    ClientScript.RegisterStartupScript(this.GetType(), "key", strScript2);

Page 1 of 1 (8 items)