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
  1. Home
  2. General Programming
  3. C#
  4. how can prevent page posting back

how can prevent page posting back

Scheduled Pinned Locked Moved C#
javascriptsysadmin
6 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    m rastgar
    wrote on last edited by
    #1

    i have a webpage with asp button. in server side, i wrote some code for its button click event to delete the page data. but in client side i want user to confirm the deletion action. so i write this javascript code: {if(confirm("do want to delete data...."))} i don't know what to do to prevent page postback for false condition. what should i do...

    Thanks Rastgar

    T G 2 Replies Last reply
    0
    • M m rastgar

      i have a webpage with asp button. in server side, i wrote some code for its button click event to delete the page data. but in client side i want user to confirm the deletion action. so i write this javascript code: {if(confirm("do want to delete data...."))} i don't know what to do to prevent page postback for false condition. what should i do...

      Thanks Rastgar

      T Offline
      T Offline
      Tom Aeqy
      wrote on last edited by
      #2

      {if(!confirm("do want to delete data....")) return; else do();}

      M 1 Reply Last reply
      0
      • M m rastgar

        i have a webpage with asp button. in server side, i wrote some code for its button click event to delete the page data. but in client side i want user to confirm the deletion action. so i write this javascript code: {if(confirm("do want to delete data...."))} i don't know what to do to prevent page postback for false condition. what should i do...

        Thanks Rastgar

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

        Return a boolean in the click event of the button: onclick="return confirm('Delete?');" If the event returns false, the button click is stopped.

        --- b { font-weight: normal; }

        M 1 Reply Last reply
        0
        • G Guffa

          Return a boolean in the click event of the button: onclick="return confirm('Delete?');" If the event returns false, the button click is stopped.

          --- b { font-weight: normal; }

          M Offline
          M Offline
          m rastgar
          wrote on last edited by
          #4

          Thanks alot. but your sample code doesn't work or atleast i couldn't understand you and apply your method. but i found another method in other forum. here it is... { if(confirm('do you want to delete?') return true; if(document.all && window.event) event.returnValue = false; return false; } it works so much better and do what exactly i wanted.

          Thanks Rastgar

          G 1 Reply Last reply
          0
          • T Tom Aeqy

            {if(!confirm("do want to delete data....")) return; else do();}

            M Offline
            M Offline
            m rastgar
            wrote on last edited by
            #5

            i now 'if' parts and what 'return' does. the thing that i don't know is how to stop my page from postback. but now i found it. to know that refer to my reply to guffa

            Thanks Rastgar

            1 Reply Last reply
            0
            • M m rastgar

              Thanks alot. but your sample code doesn't work or atleast i couldn't understand you and apply your method. but i found another method in other forum. here it is... { if(confirm('do you want to delete?') return true; if(document.all && window.event) event.returnValue = false; return false; } it works so much better and do what exactly i wanted.

              Thanks Rastgar

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

              The code that I wrote does work, but the backwards way that this forum uses for "security" changed it. :( Remove the * in the code: o*nclick="return confirm('Delete?');"

              --- b { font-weight: normal; }

              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