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. Web Development
  3. ASP.NET
  4. How to avoid button call event on page refresh

How to avoid button call event on page refresh

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-nethelptutorial
5 Posts 4 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.
  • N Offline
    N Offline
    Nagraj Naik
    wrote on last edited by
    #1

    When ever i call asp.net button it will do what are the code inside the button. after refresh that page automatically button event call once again run the button event. How can i avoid this problem? Thanks, Nagraj.

    E 1 Reply Last reply
    0
    • N Nagraj Naik

      When ever i call asp.net button it will do what are the code inside the button. after refresh that page automatically button event call once again run the button event. How can i avoid this problem? Thanks, Nagraj.

      E Offline
      E Offline
      eyeseetee
      wrote on last edited by
      #2

      if (Page.IsPostBack == true) etc hope this helps

      C 1 Reply Last reply
      0
      • E eyeseetee

        if (Page.IsPostBack == true) etc hope this helps

        C Offline
        C Offline
        ChrisKo 0
        wrote on last edited by
        #3

        CODE HORROR! if (Page.IsPostBack) { //do stuff } Please don't evaluate a bool to a bool, it's not needed.

        N 1 Reply Last reply
        0
        • C ChrisKo 0

          CODE HORROR! if (Page.IsPostBack) { //do stuff } Please don't evaluate a bool to a bool, it's not needed.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          ChrisKo wrote:

          CODE HORROR!

          Why? There is nothing wrong with if(Page.IsPostBack == true ), this documents the intent of the code more explicitly. You could also make the argue that Page is unnecessary.


          only two letters away from being an asset

          C 1 Reply Last reply
          0
          • N Not Active

            ChrisKo wrote:

            CODE HORROR!

            Why? There is nothing wrong with if(Page.IsPostBack == true ), this documents the intent of the code more explicitly. You could also make the argue that Page is unnecessary.


            only two letters away from being an asset

            C Offline
            C Offline
            ChrisKo 0
            wrote on last edited by
            #5

            You are doing an unnecessary comparison that can be easily avoided. I haven't actually looked at the IL, but the compiler might be smart enough to ignore that comparison. That is not the main reason for avoiding that type of code though. The main reason is because it's quiet easy to do this by mistake:

            if(Page.IsPostBack = true )

            And then you've got things happening that you never expected and it's easy to miss this simple istype for hours. I agree that Page could be omitted, but as you mentioned, it makes the code more explicit in intent. It's possible that someone new to ASP.NET development takes over maintenance on this project and doesn't know that the Page object is available to him. I guess I shouldn't have said code horror, but it's something that should be avoided.

            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