gruber
gruber

Reputation: 29727

do postback after enter hit on changing text in textbox

How can I make postback after user changes textbox text and hits enter ? Is only javascript real solution. Doesnt asp.net give any out from box solution for such a problem ? Thank You for any hints.

Upvotes: 1

Views: 566

Answers (1)

Waqas Raja
Waqas Raja

Reputation: 10872

Beside the javascript solutions, you can place the textbox with a submit button inside a panel and make use of DefaultButton property of the panel.

Below is the code example: -

Your aspx will look like this

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Panel>

Now, when you press enter inside the text box the button click event occurs, same as by clicking the button.

Upvotes: 2

Related Questions