Hi mukesh1,
There is no server side KeyPress event for TextBox in ASP.Net. So you need to add a Button and make its style to display none. Then write the saving code in Button click event.
When the TextBox keypress event is fired (i.e. enter button is pressed) at client side you need to trigger the Button click event at client side.
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:Button ID="btnSave" Text="text" runat="server" Style="display: none" OnClick="Save" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=txtName]').keypress(function (e) {
if (e.keyCode == 13) {
$('[id*=btnSave]').trigger('click');
return false;
}
});
});
</script>
Code
protected void Save(object sender, EventArgs e)
{
string name = txtName.Text;
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Name is : " + name + "')", true);
}
Screenshot