Pouki Pouki - 1 year ago 68
ASP.NET (C#) Question

ASP.NET DefaultButton is focused on page load

I'm setting the propriety

on my asp form, in order to send the form on the key

Everything is working fine, but my button has the focus state on the page load which is bothering because of some CSS styles applied on the page.

<form id="loginForm" runat="server" DefaultButton="btnLogin">

I would like the button to not be focused on the page load.

Thank you for your help

Answer Source

This is the default behavior of default button in ASP.NET. What you can do to override that is to set default focus manually on some other control. To do so, call Page.SetFocus:


This will set focus control on the form like that:

<form id="loginForm" runat="server"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download