Results 1 to 2 of 2

Thread: Why do I sometimes have to click button twice to fire BUTTON.CLICK event?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    1

    Why do I sometimes have to click button twice to fire BUTTON.CLICK event?

    To illustrate the problem I am experiencing I have created a very simple form "WebForm2". It has a button that is wired to fire the Button1.Click event. Both the Page_Load and Button1_Click subroutines increment their respective counters - which are displayed on the page as the number of times each has been executed.

    If I compile and execute this web form it runs perfectly!!!

    It increments the Page_Load counter as expected when the page is first displayed. Thereafter, both counters are incremented each time the button is clicked.

    So far so good. However, if I transfer control to this form from another using Server.Transfer it does not work as expected. See "WebForm1" which simply transfers control to "WebForm2".

    Now when WebForm2 is displayed, it again shows that Page_Load has already been exectuted once. But clicking on the button does nothing! It just seems to refresh the page...

    Clicking on the button a second (and subsequent) times increments both counters as it is supposed to.

    What is going on here? Please help.

    I have tried extensive searches of the Internet and not found a solution for this particular problem. I have tried changing many of the default settings for the button - without any success. I have tried setting Auto-wireup to true - that also did not work.

    I have created these simple forms - to illustrate a general problem because the actual application is very complicated. I can however offer a little additional information from the actual application.

    In the application, there is a text box into which the user is supposed to type an account number before clicking the button. The information in the text box is cleared when the button is clicked for the first time. There is also validation on the contents of the text box and that runs on the first click - displaying an error if an invalid value is entered. But as already indicated, if a valid value is entered, it simply disappears.

    This behaviour is consistent throughout the whole application - or on every page except the first. On the page to enter contact details, first click wipes out all the data, second click works correctly. But if you call the contact details update page directly from your browser, it works perfectly. Call it using Server.Transfer and it has this problem.

    All code and HTML for the sample WebForms can bee seen in the attached file.

    Code.txt

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: Why do I sometimes have to click button twice to fire BUTTON.CLICK event?

    just as a test, have you tested what happens when you click somewhere else on the page first, THEN click the button? It may not have focus.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width