Programmatically Submit Form on Enter Key in C#

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

Helpful Unix Commands – SCP

SCP is useful to securely copy a file or directory from one Unix server to another Unix server.

After logging into one Unix server, type the following command to copy a directory from the currently logged on server to serverB:

scp -p -r file_name serverB:/dir/test/

The -p parameter copies the permissions, and -r copies recursively for a directory.

Enable Line Numbers In Visual Studio 2010 for C#

To enable line numbers along the left side of your code (which makes for easier debugging tool), simply navigate to Tools > Options to open the Options Window.

In the Options Window, navigate to Text Editor > C# > General. In the screen, there is a checkbox called Line Numbers. Insure the check box is checked. These quick steps will enable the line numbers only for C#.

To take this procedure a step further, if you’d like to enable Line Numbers on all languages (and not just only C#), instead of selecting C#, there is another option on that level of the hierarchy called All Languages that displays the same checkbox (under General) with a checkbox that toggles Line Numbers in all languages.