Enter Key in ASP.NET TextBox Control


 

Easy solution for default button

There is a free component that allows you to assign a button to the “enter-pressed” client side event of input controls. If you type some text in textbox and press Enter, the form will postback, and the serverside click event of your button is fired. You don’t need to write any code, but you only need to use this control’s “DefaultButton” property. It you are a beginner programmer this could be a life saver. More about MetaBuilders DefaultButtons Control you can find at http://www.metabuilders.com/Tools/DefaultButtons.aspx

Default buttons in ASP.NET 2.0 and ASP.NET 3.5

ASP.NET 2.0 makes this problems easier and introduce a concept of a “default button”. New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be “clicked” depends of where actually cursor is and what button is chosen as a default button for form or a panel.

Here is sample HTML code that contains one form and one panel control:

<form defaultbutton=”button1″ runat=”server”>
    <asp:textbox id=”textbox1″ runat=”server”/>
    <asp:textbox id=”textbox2″ runat=”server”/>
    <asp:button id=”button1″ text=”Button1″ runat=”server”/>
    <asp:panel defaultbutton=”button2″ runat=”server”>
        <asp:textbox id=”textbox3″ runat=”server”/>
        <asp:button id=”button2″ runat=”server”/>
    </asp:panel>
</form>

ASP.NET Tutorials: Enter Key in ASP.NET – Complete Research

About these ads

3 thoughts on “Enter Key in ASP.NET TextBox Control

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s