The DevExpress template creates a web app including a Login.aspx and Register.aspx. I have noticed the click code for btnLogin as well as btnCreate runs twice every time the buttons are pressed. This causes an error when creating a user because it tries to create the same user twice. After a great deal of experimenting, I have found a workaround by turning off the "UseSubmitBehavior" as follows:
ASPx<dx:ASPxButton ID="btnLogin" runat="server" Text="Log In" ValidationGroup="LoginUserValidationGroup"
OnClick="btnLogin_Click" UseSubmitBehavior="false">
</dx:ASPxButton>
<dx:ASPxButton ID="btnCreateUser" runat="server" Text="Create User" ValidationGroup="RegisterUserValidationGroup"
OnClick="btnCreateUser_Click" UseSubmitBehavior="false">
</dx:ASPxButton>
What is causing the click event to run twice? Is it correct to turn off the "UseSubmitBehavior"?
Hi Larry,
I created a sample project using our template. However, I did not manage to reproduce the issue. The ASPxButton.Click event handler code runs just for one time as expected. Take a look at the attached video.
Please send us your sample project illustrating the issue so we can analyze it and provide a solution.
I have created a sample project using your template and the click event runs twice most of the time but not always. I have used Session Variables to record if the click event runs twice. Usually, it only runs once on the first login but, after that, it nearly always runs twice.
I still cannot reproduce the issue. The click event runs once. However, I see why the "SecondPass" session variable may contain data. When pressing the browser back button to return from the Default page to the Login page, the "FirstPass" session variable is not null, so the "Text" property of the tbPassword control is recorded to the "SecondPass" session variable. To avoid this situation, you can remove session variables in the Page.Load event handler:
I've created a video to illustrate this.
If you still have the issue, would you please send me a video (you can create it using a free ShareX tool) demonstrating how to reproduce it?
I use the "Remove Session Objects" button to redirect to the login page,not the browser Back button. The button removes both session objects before redirecting to login page so neither one exists on Page Load.
I tested your project using the "Remove Session Objects" button with the same result - the ASPxButton.Click event fires just once. Please take a look at the new video. If I missed something in my testing scenario, please describe steps to reproduce the issue in greater detail. Also, please check your project in a different web browser or on another developer machine. Another suggestion is to make sure that ASPxButton is not clicked twice, for instance using a double-click. In this case, a page sends two requests to the server, so the ASPxButton.Click event may fire twice.
I don't understand why your IIS is behaving differently. It happens on my development computers and at my client sites.
It is difficult to find the cause of the issue without debugging it. Note that the ASPxButton.UseSubmitBehavior property is set to "True" by default, so ASPxButton uses a client browser's submit mechanism. If you specify false, the ASP.NET postback mechanism is used. Also, please refer to the How to prevent double clicking or multiple Form submission after the ASP.Net Button is clicked? article, which may help you resolve the issue.