To make a button default button we can use the following C# code.
Page.Form.DefaultFocus = txtCprNumber.ClientID;//Setting default focus element Page.Form.DefaultButton = btnSearch.UniqueID;// Setting default button
But let’s think that we have a logout button on top of the page in control and placed on top of every page.
So what happening:
1) For the browser’s default behavior the "logout" button are getting default focus.
2) When user pressing enter to a textField the logout button is getting clicked because of the default browser behavior and actually the user is unaware of that.
Lets try some solution:
1) The solution would be for every page make a button of that page as default button. But that very costly.
2) Making sure the "Logout" button is not in focus, hmm an centralized solution.
BUT, I found a straight forward solution by just adding an ASP button property. i.e. UseSubmitBehavior and set it to true.
Now the logout button is no longer in the foucs.
<asp:Button ID="btnLogout" runat="server" Text="Logout" CssClass="logoutButton" OnClick="btnLogout_Click" UseSubmitBehavior="false" />
OK. Its works for every browser!!!