I am very new to the world of aspx, web forms. But I am assigned to development of webform due to some circumstances. I am somehow struggling and surviving in this. I have a problem, may be if someone who is familiar with this, can help me understand is very much appreciable.
Problem: I am created a search box functionality successfully in an aspx webform with codebehind as vb. But the problem is, when I type some text in this search box and press enter, it reloads to initial state rather than show up the search results. It works well when we just type text in it and do not press enter. For every letter I type in the box, in displays with matching search results. I just am wondering why is this not working if I type text and press enter at the end of text for example like google search. For ex: I typed "test" in searchbox and press enter. Results appear perfect until I press enter key. Once I press enter, it goes back to original state how ever it was.
Investigation:
I debugged it and found that when enter is pressed, the value in textbox becomes empty. I am unable to understand why is it getting empty even if text is present in text box. I tried onkeypress="return event.keyCode!=13" in
<asp:TextBox ID="SearchTextBox" runat="server" onkeypress="return event.keyCode!=13" CssClass="txt"></asp:TextBox> so as not to return empty value when enter is pressed. But it did not work.
Dim searchkey As Stringsearchkey = SearchTextBox.Text.
searchkey returns emtpy string and not "test" string. But why? How can I overcome it?
Looking for: Is there a possibility that I can get the text value present in textbox when enter is pressed.
I appreciate your help and new learning for me






Do not use onkeypress directly like this onkeypress="return event.keyCode!=13"
create a common js file and use it anywhere you want, you can modify also in one js.
use common js file and create a function and use on your code via link like this
<script src="~/js/common.js"></script>Here is the js code to prevent Enter key:
and use in your code like this:
hope this will help you