Friday 11 July 2014

Setting Default Button in ASP.Net or The DefaultButton of 'form1' must be the ID of a control of type IButtonControl Error

Default button on a form always gets triggered when we press 'Enter' key on the keyboard. This always reduces the usage of mouse clicks on the button (ex: submit button to submit a form), and it helps the user to save time. ASP.NET 2.0 has exposed a DefaultButton property of the form object that allows you to set the button that will be used as the default when the user presses the Enter key. ASP.NET then handles the client script generation for you.
Page.Form.DefaultButton = btnLogin.UniqueID
For Focus:
Page.Form.DefaultButton = btnLogin.ClientID