Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Postback problem from ASP.NET page

Postback problem from ASP.NET page

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelpquestion
10 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LancashireLad
    wrote on last edited by
    #1

    I am trying to use a client side confirm dialog box. I have a generic sub (borrowed from an article by Jim Stall) that successfully generates the client side Yes/No dialog box. According to the forums and docs I've read, a postback should only occur if the user clicks OK. This means my server code should only needs to check if OK was pressed. The behavior I'm finding is that a postback occurs regardless of whether the user clicks OK or Cancel. This means I can't detect what was selected. Can someone suggest what I'm doing wrong? Here's the server side code: Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub The button declaration code: The page load code that calls the button generation code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then eVSUtils.CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") End If End Sub Any suggestions on why it does a postback regardless of the button pressed? Thanks!

    M G F 3 Replies Last reply
    0
    • L LancashireLad

      I am trying to use a client side confirm dialog box. I have a generic sub (borrowed from an article by Jim Stall) that successfully generates the client side Yes/No dialog box. According to the forums and docs I've read, a postback should only occur if the user clicks OK. This means my server code should only needs to check if OK was pressed. The behavior I'm finding is that a postback occurs regardless of whether the user clicks OK or Cancel. This means I can't detect what was selected. Can someone suggest what I'm doing wrong? Here's the server side code: Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub The button declaration code: The page load code that calls the button generation code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then eVSUtils.CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") End If End Sub Any suggestions on why it does a postback regardless of the button pressed? Thanks!

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      LancashireLad wrote:

      a generic sub (borrowed from an article by Jim Stall)

      I'm not sure what you are referring to.. Have you checked this one?? Custom Javascript Dialog[^]

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

      L 2 Replies Last reply
      0
      • M Michael Sync

        LancashireLad wrote:

        a generic sub (borrowed from an article by Jim Stall)

        I'm not sure what you are referring to.. Have you checked this one?? Custom Javascript Dialog[^]

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

        L Offline
        L Offline
        LancashireLad
        wrote on last edited by
        #3

        Thanks, I'll take a look at the samples you pointed to!

        1 Reply Last reply
        0
        • M Michael Sync

          LancashireLad wrote:

          a generic sub (borrowed from an article by Jim Stall)

          I'm not sure what you are referring to.. Have you checked this one?? Custom Javascript Dialog[^]

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

          L Offline
          L Offline
          LancashireLad
          wrote on last edited by
          #4

          Michael, Thanks for pointing me to the blog you did on using the prompt funtion. It's helpful but is not solving the problem I'm having. I'm a novice Javascript programmer so it may be something elemental that I'm missing. According to articles I've read on using confirm() is that if the user clicks Cancel to the OK/Cancel prompt, nothing happens (which is what I want). If they click OK, a postback occurs and executes the code in my button click event. What I'm finding is that regardless of whether OK or Cancel is clicked, the client does a postback. This means I have no way of knowing whether they clickede OK or Cancel. Original article: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx (see response http://www.thescripts.com/forum/thread115874.html) I hope this makes sense and thanks in advance for any help.

          M 1 Reply Last reply
          0
          • L LancashireLad

            I am trying to use a client side confirm dialog box. I have a generic sub (borrowed from an article by Jim Stall) that successfully generates the client side Yes/No dialog box. According to the forums and docs I've read, a postback should only occur if the user clicks OK. This means my server code should only needs to check if OK was pressed. The behavior I'm finding is that a postback occurs regardless of whether the user clicks OK or Cancel. This means I can't detect what was selected. Can someone suggest what I'm doing wrong? Here's the server side code: Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub The button declaration code: The page load code that calls the button generation code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then eVSUtils.CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") End If End Sub Any suggestions on why it does a postback regardless of the button pressed? Thanks!

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            You are only adding the event the first time the page is loaded. If you do a postback for any reason, the event isn't added to the control when the page loads again. Verify that the code is actually present in the generated code, and if it is, show us what the generated code looks like.

            --- single minded; short sighted; long gone;

            L 1 Reply Last reply
            0
            • G Guffa

              You are only adding the event the first time the page is loaded. If you do a postback for any reason, the event isn't added to the control when the page loads again. Verify that the code is actually present in the generated code, and if it is, show us what the generated code looks like.

              --- single minded; short sighted; long gone;

              L Offline
              L Offline
              LancashireLad
              wrote on last edited by
              #6

              Thanks for responding. I removed the IsPostBack on the load event and it made no difference. The confirm function is executing. The generated code is below. If you hit cancel I was under the impression that no postback would occur. However, it does and the button code click event fires on the server when you click cancel. Is it your understanding that a postback should not occur if you click Cancel on a confirm dialog box? [Delete](javascript:__doPostBack('btnDelete','')) function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } Thanks for your time.

              1 Reply Last reply
              0
              • L LancashireLad

                I am trying to use a client side confirm dialog box. I have a generic sub (borrowed from an article by Jim Stall) that successfully generates the client side Yes/No dialog box. According to the forums and docs I've read, a postback should only occur if the user clicks OK. This means my server code should only needs to check if OK was pressed. The behavior I'm finding is that a postback occurs regardless of whether the user clicks OK or Cancel. This means I can't detect what was selected. Can someone suggest what I'm doing wrong? Here's the server side code: Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub The button declaration code: The page load code that calls the button generation code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then eVSUtils.CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") End If End Sub Any suggestions on why it does a postback regardless of the button pressed? Thanks!

                F Offline
                F Offline
                Fred_Smith
                wrote on last edited by
                #7

                This is very odd - yes, hitting Cancel shouold stop the postback; and you are also quire correct in that you need only add the JS once, the first time the page is loaded. There really is no reason I can see why this shouldn't work - unless you have javascript disabled in your browser, perhaps..? The simple page below, based on your code, works fine for me in both IE and Firefox - try copying it to your web-folder and running it. If it works, then there is something going on elsewhere on your page... Fred <%@ Page Language="vb" debug="true" %> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") else litX.text += "Postback<br>" End If End Sub Private Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub

                L 1 Reply Last reply
                0
                • L LancashireLad

                  Michael, Thanks for pointing me to the blog you did on using the prompt funtion. It's helpful but is not solving the problem I'm having. I'm a novice Javascript programmer so it may be something elemental that I'm missing. According to articles I've read on using confirm() is that if the user clicks Cancel to the OK/Cancel prompt, nothing happens (which is what I want). If they click OK, a postback occurs and executes the code in my button click event. What I'm finding is that regardless of whether OK or Cancel is clicked, the client does a postback. This means I have no way of knowing whether they clickede OK or Cancel. Original article: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx (see response http://www.thescripts.com/forum/thread115874.html) I hope this makes sense and thanks in advance for any help.

                  M Offline
                  M Offline
                  Michael Sync
                  wrote on last edited by
                  #8

                  Did you check the sample? There are two parts (using normal js confirm and js custom dialog)in this article. there is a way to know whether the user clicks "delete it" button ("OK" button in your case), "cancel " button and "close" button at the top of custom dialog.

                  it said:

                  If the user click “cancel” or “close” image, we call “hideWindow()” function. In this function, we hide the JS dialog and set the variable “g_IsWindowShown” to true. (We also return “false” in this function since we dont want the Server-side code to execute.) If the user click “Delete It” button then we call “deleteit()” function. In this function, we set the text of textbox to hidden field so that this value can be read from Server-side script. then, we fire the button client event of “Delete” button (not “Delete It” button.) then, showWindow() function will be invoked again. At that time, the variable “g_IsWindowShown” will be true. After that, we just return “true” from this function. So, the Server-side code will be executed.

                  Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                  1 Reply Last reply
                  0
                  • F Fred_Smith

                    This is very odd - yes, hitting Cancel shouold stop the postback; and you are also quire correct in that you need only add the JS once, the first time the page is loaded. There really is no reason I can see why this shouldn't work - unless you have javascript disabled in your browser, perhaps..? The simple page below, based on your code, works fine for me in both IE and Firefox - try copying it to your web-folder and running it. If it works, then there is something going on elsewhere on your page... Fred <%@ Page Language="vb" debug="true" %> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then CreateConfirmBox(btnDelete, "Are you sure you want to delete this user?") else litX.text += "Postback<br>" End If End Sub Private Sub CreateConfirmBox(ByRef btn As WebControls.LinkButton, ByVal strMessage As String) btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');") End Sub

                    L Offline
                    L Offline
                    LancashireLad
                    wrote on last edited by
                    #9

                    Fred, Thanks for confirming that I am not going crazy! I cut and pasted your code into an empty ASPX form and still get the same behavior. When I click Cancel on the confirm() dialog, it does a postback! :confused: I've tried running the code from a local IIS and from an ISP and get the same behavior. Unless, you have any suggestions, I guess I need to open an incident with Microsoft to get to the bottom of this. Thanks!

                    L 1 Reply Last reply
                    0
                    • L LancashireLad

                      Fred, Thanks for confirming that I am not going crazy! I cut and pasted your code into an empty ASPX form and still get the same behavior. When I click Cancel on the confirm() dialog, it does a postback! :confused: I've tried running the code from a local IIS and from an ISP and get the same behavior. Unless, you have any suggestions, I guess I need to open an incident with Microsoft to get to the bottom of this. Thanks!

                      L Offline
                      L Offline
                      LancashireLad
                      wrote on last edited by
                      #10

                      Okay, The mystery is solved. It turns out that I'm running McAFee antivirus software. It has two browser components that are meant to catch phishing activities. I disabled these two comnponents and everything works fine. BTW, McAfee SUCKS. They have been sending out daily builds recently requiring reboots. These guys are clueless. Note to self, GET RID OF MCAFEE :mad: Thanks to all for helping me work through this.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups