ASP.NET

Moti Mashiah
Moti Mashiah used Ask the Experts™
on
HI guys,
I have asp.net application and have button which is implemented on the server side.

<asp:TextBox ID="txtObject" onfocus="this.select();" runat="server" AutoPostBack="True" CssClass="form-control"></asp:TextBox>

Open in new window


I would like to fire this textbox just when user click ENTER key = 13, for now I used the method onchange "txtObject_TextChanged" as it is the only option i have in asp.net.

The issue I have is if I change anything in the textbox it postback and I would like to postback just when I press enter in the textbox.

I also tried to setup the  AutoPostBack to false and It didn't worked for me as if you set it to false the enter key will not work as well.

please any suggestions.

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Team Lead
Commented:
The issue I have is if I change anything in the textbox it postback and I would like to postback just when I press enter in the textbox.
you no need to do any changes to your existing ASP control:

the below code is good enough for you.

<asp:TextBox ID="txtObject" onfocus="this.select();" runat="server" AutoPostBack="True" CssClass="form-control"></asp:TextBox>

hence you no need to add the TextChanged to detect the enter key, unless you need to use it for other process?
Ryan ChongSoftware Team Lead

Commented:
any further clarification is needed here?
Moti Mashiah.NET Developer

Author

Commented:
thanks, its solve my issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial