This is a textbox field I have and when a user enters in a value and hit enter, I want the value to submit when the user hit enter.
<div id="divUserInfo" >
<table align="center">
<tr id="trDomain" runat="server" visible="false">
<td class="tdLabel tdLabelInfo" >Domain Name</td>
<td class="tdData">
<asp:TextBox ID="txtDomain" runat="server" ToolTip="Network domain user is associated."></asp:TextBox>
<asp:Label ID="lblRqdDom" runat="server" Text="required" CssClass="noshow" ></asp:Label>
</td>
</tr>
Yes I know I’m formatting in a table and will not being using tables for my future projects.
Postback on TextBox loosing focus
If you just want to do a postback when
TextBoxlooses focus (by pressingEnter,Tabor moving focus to another control), setAutoPostBackproperty of theTextBoxto true.After writing something in the
TextBoxand making it loose focus, you’ll get a postback. I suppose, however, that this can be raised not only on pressing Enter.More information on MSDN: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.autopostback.aspx.
Postback by simulating submit Button click on pressing Enter
If you want a postback only on pressing enter, you can put add a
Buttonon the page and put it with theTextBoxin the samePanelcontrol. Then you should setDefaultButtonproperty for thisPanel. This should invoke button click on pressing Enter when theTextBox(or any other control in thePanel) is focused.So, your code can look like this (the code hasn’t been tested):
You can find more information about it here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx.
If you have any issues applying any of those solutions or further questions, let me know.