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. WPF
  4. How can I prevent a user to click a button more than once

How can I prevent a user to click a button more than once

Scheduled Pinned Locked Moved WPF
questiondatabase
5 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.
  • F Offline
    F Offline
    fiaolle
    wrote on last edited by
    #1

    Hi When the button is clicked it changes to another page (UserControl), but if they click the button fast a couple of times it crashes. That is because the service isn't finished with getting data from the database, which the other pages need. I don't want to use IsEnabled=false, is there another way? Thanks Fia

    P 1 Reply Last reply
    0
    • F fiaolle

      Hi When the button is clicked it changes to another page (UserControl), but if they click the button fast a couple of times it crashes. That is because the service isn't finished with getting data from the database, which the other pages need. I don't want to use IsEnabled=false, is there another way? Thanks Fia

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Why do you not want to do IsEnabled=false? An alternative could be to set a flag when you click the button the first time and reset it when the service has finished getting data; then it wouldn't matter whether or not the user multipresses the button, you won't make the call until the flag says it's okay to do so.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      F 1 Reply Last reply
      0
      • P Pete OHanlon

        Why do you not want to do IsEnabled=false? An alternative could be to set a flag when you click the button the first time and reset it when the service has finished getting data; then it wouldn't matter whether or not the user multipresses the button, you won't make the call until the flag says it's okay to do so.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        F Offline
        F Offline
        fiaolle
        wrote on last edited by
        #3

        Hi Thanks for your reply But it doesn't work with IsEnabled, I use that button to navigate to a different page, and the button is the same for every page. In one page the user writes the his username and password. If It's right I get the data from that user and move on to a different page when that button is clicked. In another page the users can choose someting from a combobox, when that is choosen and the button is clicked, the data is fetched regarding what was choosen in the combobox. I tried to use IsEndabled=false, but if the user clicks several times, it navigates several pages. It seems like the the button clicks are saved and when the button's IsEnabled=true, it moves the count that the button was clicked. Please help Fia

        P 1 Reply Last reply
        0
        • F fiaolle

          Hi Thanks for your reply But it doesn't work with IsEnabled, I use that button to navigate to a different page, and the button is the same for every page. In one page the user writes the his username and password. If It's right I get the data from that user and move on to a different page when that button is clicked. In another page the users can choose someting from a combobox, when that is choosen and the button is clicked, the data is fetched regarding what was choosen in the combobox. I tried to use IsEndabled=false, but if the user clicks several times, it navigates several pages. It seems like the the button clicks are saved and when the button's IsEnabled=true, it moves the count that the button was clicked. Please help Fia

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          You could always change it's visibility so that it can't be clicked, and only make it visible when it's the right time to do so.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          J 1 Reply Last reply
          0
          • P Pete OHanlon

            You could always change it's visibility so that it can't be clicked, and only make it visible when it's the right time to do so.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            J Offline
            J Offline
            Jeremy Likness
            wrote on last edited by
            #5

            Easiest way is just to mask the button. Put a rectangle in the same container that is the width/height of the button and make it transparent. When inside grids, etc, order matters - the rectangle should be represented AFTER the button so it is in the foreground. By default, set the visibility to collapsed. When the user clicks, set it to visible until you are done initializing, then collapse it again. It will mask any clicks or UI events but not fudge the UI.

            <Grid>
            <Button/>
            <Rectangle Fill="Transparent"/>
            </StackPanel>

            Jeremy Likness
            Latest Article: Whats in Your Collection? Part 1 of 3: Interfaces
            Blog: C#er : IMage

            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