Using alert in ASP.NET 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ITCraze
    New Member
    • Nov 2007
    • 19

    Using alert in ASP.NET 2005

    I am using alert, when user has successfully inserted the values in database.


    for ex:

    Response.Write( "<script>alert( "You have successfully inserted values");</script>");

    This code successfully runs, but the problem is that when I press the back button in my application from any page , this alert box also appears.
    I don't want alert window to appear when clicking on Back button.

    Please suggest what should I do.

    Thank you.
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    probably u need to have one variable use it as a flag to determine the success and failure operation and reset that after your alert message.
    Also check for the caching in your page for back button problem.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      I would guess that you are doing something in the page_load() function that is either not switched on by the isPostback variable, or should be performed elsewhere.

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        As Plater said you should check your Page_Load method. In addition to that you could create a label and set the Text property = to the javascript alert.

        Code:
        lblMessage.Text = "<script>alert('Inserted Successfully');</script>";
        You can then use the Visible property to hide or display this message at the appropriate time.

        So in the Page_Load method set your label's visible property to false. In the button click event (or whatever control inserts records) change the label's visible property to true.

        Nathan

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          It's may not be your server side Page_Load that's being called.
          It's the fact that your script runs when your html page is loaded.

          You should use a hidden field that is set to "true" when the user clicks "ok" in your alert box. This hidden value can be used by your JavaScript (to prevent it from running during your window.onload event) and can also be used by your Server Side code (to prevent the JavaScript for the alert from being sent to the browser at all).

          -Frinny

          Comment

          Working...