Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Preventing more than 1 clic on a form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Preventing more than 1 clic on a form

    Steve - I believe the issue is that (even in your example) all of Validate has to finish and make it over to AfterValidate before the session variable flag gets set. If the button is pressed twice in the first few seconds, it runs the Validates concurrently so they both make it past the check before AfterValidate has a chance to set the variable.

    I tried to correct for this by setting the variable in AfterValidate and using an IF THEN there. I believe in theory it should work, but it doesn't. Like I mentioned earlier it is like WAS lets both Validates finish, then starts the AfterValidates concurrently so the second click doesn't see that the variable was set.

    Initialize:
    session.AfterValCheck = "a"

    AfterValidate:
    session.AfterValCheck = session.AfterValCheck + "b"
    If session.AfterValCheck = "ab" Then
    ... add stuff to tables
    Else
    ...Do nothing
    end if

    Comment


      #17
      Re: Preventing more than 1 clic on a form

      I didn't just type the code here, I tested it. No matter how fast or slow I click the button, it always works. What did you do different in one of the events?
      Steve Wood
      See my profile on IADN

      Comment


        #18
        Re: Preventing more than 1 clic on a form

        I did try the code exactly as you had it, but it still exhibited the problem. I think the biggest difference between what I have and what you are testing is how much is being done in Validate. I have a few lookups and tablecounts to validate the data which can take a little while.

        I appreciate your code and wish I could have gotten it to work in my dialog.

        Comment


          #19
          Re: Preventing more than 1 clic on a form

          I believe (assume) it was Ira who has previously talked about concurrency and atomic operations, and I think I've tried to explain this here before as well. While it is difficult to say with 100% certainty what is going on because it is timing dependent, it is entirely possible that what Paul has offered as a suggested reason is exactly what is happening.

          While the server does not give preference to one specific event over another, it is a multi-threaded and multi-user environment. Processing will switch from request to request as with any multi-tasking system and you do not have control over when or if a switch will happen. Because the variable is tested and then some lines of code later it is set to lock out other processing, there is a window of opportunity for other processing to also test it between the original test and the set.

          Because of this, it is entirely possible for processing to run something like
          1. request 1 validate (variable is not set, so processing continues)
          2. request 2 validate (variable is not set, so processing continues)
          3. request 3 validate (variable is not set, so processing continues)
          4. request 2 AfterValidate (sets the variable)
          5. request 3 AfterValidate (sets the variable again)
          6. request 1 AfterValidate (sets the variable again)

          The exact order that things process in will not always be the same and can be difficult to reproduce. But in the case above, you would effectively process 3 button clicks even though you only want one.

          Xbasic does not provide an easy way to enforce a critical section, but one way to approximate it is with a file lock. In your validate section attempt to get an exclusive lock on a common file. If it succeeds, no other process is trying to run and you can continue and make sure you unlock the file when you are done. If it fails, other processing is going on and you can either stop processing (as in the case of only allowing a single button click here), or wait some time period and try again.

          -Lenny

          Lenny Forziati
          Vice President, Internet Products and Technical Services
          Alpha Software Corporation

          Comment


            #20
            Re: Preventing more than 1 clic on a form

            I think I'm becoming too sure of myself.
            Steve Wood
            See my profile on IADN

            Comment


              #21
              Re: Preventing more than 1 clic on a form

              Thanks Lenny, I will give it a try. This is what I will attempt:

              INITIALIZE:
              ..create a file


              AFTERVALIDATE:
              ..try to lock file
              ..if successful, add data to tables, unlock file
              ..else wait until file can be locked then response.redirect
              to success page

              Comment


                #22
                Re: Preventing more than 1 clic on a form

                Steves approach works for me (i dont want to get into any computer science theory discussion) although i understand its not perfect.

                just one las thing
                when the button gets clicked twice the form will redirect to that same form, and i want it to go to another page I tried the following without success

                '----------------
                if eval_valid("session.isclicked")
                CurrentForm.Has_Error = .t.
                Currentform.RedirectTarget = "tabbed_emisiones_edit.A5W"
                else
                '..any other validation code
                end if
                '-----------------
                Cheers
                Mauricio

                Comment


                  #23
                  Re: Preventing more than 1 clic on a form

                  If you set CurrentForm.Has_Error to true, its going to follow the dialogs normal error process and will not (I don't think) perform any redirect. The redirect has to take place in the aftervalidate event.
                  Last edited by Steve Wood; 02-01-2008, 01:49 PM. Reason: removed "not"
                  Steve Wood
                  See my profile on IADN

                  Comment


                    #24
                    Re: Preventing more than 1 clic on a form

                    My after validate event ends with the las line saying:

                    Currentform.RedirectTarget = "tabbed_emisiones_edit.A5W"

                    the Problem is that when the button gets more than 1 click it will not continue to execute the after validate event (I think)
                    Cheers
                    Mauricio

                    Comment


                      #25
                      Re: Preventing more than 1 clic on a form

                      Mauricio, Paul also talked about using JavaScript to disable the button upon the first click and using the server code as a fail-safe. This is the recommended solution and is the way I suggest you do it. The server is going to do what is asked of it, so you really want to control things at the point of what the application user can request. This is the same principal of disabling a button in a desktop application.

                      When the button is first clicked, the browser sends the data to the server and the server begins working to create a new record. When the button is clicked a second time, the browser sends a second request. The server works on both requests, creating a record for the first one and redirecting or displaying an error for the second, depending on what you code. But the browser has abandoned the first request in favor of the second and it will only display the response to that second click.

                      The other option is to do as Steve suggested earlier on and instead of using the events to create your record, have it instead go immediately to a different page with a message such as "Saving data, please wait." That page would then do a redirect to the code that does the record creation. It's a few more steps, but the intermediate page will load quicker and will not have a button to be clicked a second time. This is a bit more work though and could still result in the same multiple click problems if the intermediate page does not load "quick enough" for your users so I would still use JavaScript to disable the button with this approach.

                      What is really gained with this technique is a more visual indication that work is being done (whole new message instead of just a disabled button) which can potentially give your application a more polished appearance. The downside to this is that the overall time to get everything done will be slightly higher due to the extra page load in between.

                      -Lenny

                      Lenny Forziati
                      Vice President, Internet Products and Technical Services
                      Alpha Software Corporation

                      Comment


                        #26
                        Re: Preventing more than 1 clic on a form

                        Lenny I tried that aproach but it seems that the browser doesnt goes to the next a5w page until it is fully loaded and considering that the xbasic code is loaded before the html (I think) theres no practical diference between putting this "Now loading" page and not doing so.

                        Unless im doing somethin wrong.
                        Cheers
                        Mauricio

                        Comment

                        Working...
                        X