By default, a majority of the pages and all the functions on a C# Web Application page are all contained within a single form element. Therefore, there may be multiple buttons or other postback controls within a single form. And this may be the reason why there isn’t by default a control which is automatically called when the web users hits the ENTER button.
To Assign a Default On a Standard C# Webpage
This is the default way and involves the name of the control. If you have a ASP Button called btnSearch, the code you would include in the Page_Load function.
this.Form.DefaultButton = “btnSearch”;
To Assign a Default On a Content Page (from a MasterPage) C# Webpage
If your Web application uses MasterPages and you want to assign a control to submit the form on the Enter key, you concept is the same as above, but you’ll need to pass the UniqueId of the control. Assume a control called btnSearch on a ContentPage, add the following to the Page_Load function.
this.Form.DefaultButton = btnSearch.UniqueId;
Some benefits to programmatically assigning the Enter key is your ability to change which Postback function to assign based on how the web user enters the page. Other than that, assigning the default submit control is a major convenience factor for web users.
References:
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton.aspx
RSS Feed
Posted in
Tags: 


