Reputation: 1810
How do I call server side code for textbox's in asp.net when user presses enter key? Code behnid method is creating a dynamic control based upon a LINQ query from data table.
Upvotes: 0
Views: 1553
Reputation: 3164
In my opinion OP want to submit data with pressing enter in the textbox
, then do sth with string
from textbox
.
So if I understand it right here is solution to do this:
//aspx
<asp:Panel ID="pnlSubmit" runat="server" DefaultButton="btnSubmit">
<asp:TextBox runat="server" ID = "txbText"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</asp:Panel>
//aspx.cs
protected void btnSubmit_Click(object sender, EventArgs e)
{
string textFromTextBox = txbText.Text;
//do sth with that string
}
Upvotes: 1
Reputation: 1249
The textbox has a TextChanged event that will fire when the focus leaves the textbox. If this isn't good enough for you, your going to need to use javascript and the onkeypress event. As there's no description of what your doing after the event, I'm not sure what to offer as sample code.
Upvotes: 2