I have created a login page with an asp:Login control. It uses a textbox for Username and one for password. In the same page I have a drop down list that sets its value according to the username entered. The username textbox has autopostback=true for this reason. Then the user enters the password and presses the submit button. Unfortunately, in the case when the user has saved the username & password to the browser, when the login page is loaded the textboxes are already populated. So when the user presses immediately the submit button without clicking anywhere else the postback is being triggered and the drop down list gets a value and the user has to press the submit button again in order to login. So the user needs two clicks which is something I want to prevent from happening.
Is there a way from code to do this : If the browser populates the Username textbox by itself, catch the username and immediately set the value of the drop down list. Then the user clicks just once the submit button.
So is there an event or something in order to know if the browser has populated the username textbox and get it at page load?
Thank you in advance!
Addition: the only code I have for the login control is this:
protected void LoginUser_LoggedIn(object sender, EventArgs e)
{
string error = "";
string User_Name = LoginUser.UserName.ToString();
if (Common.Is_Inactive_User(User_Name, ref error) || error != "")
FormsAuthentication.SignOut();
Roles.DeleteCookie();
Session.Clear();
}
which happens after the submit button is clicked. I dont have the rest of the code right now because it is at work. But I only have an event on textchanges of the username textbox to get its text and set the value of my drop down list, so it would not help. When I try to get text from the username textbox on load the code cannot see it, it returns "" (empty).
It is not always recommended but I think shortest fix could be you call the button click event from code behind instead user press the button second time. As you mentioned, so when Postback is being triggered and the drop down list gets a value then you can call the button click event to avoid the second click from user: Whatever your button click event is you can call like: