asp:TextBox - TextChange Event (Enter Key Does Not Work)

P

PD

The TextChanged event is not being called when I hit the "Enter" key.
Yet it does for the "Tab" key. I set a break point in the Page_Load
event and the TextChanged event and none of these get called when I
hit the 'Enter' key. After typing in letters in the textbox, if I hit
the 'Tab' key or click outside the text box with my mouse, the event
fires.

Here's the code:

<form id="frmArticle" name="frmArticle" method="post" runat="server">
.......
.......
<asp:textbox id="txtSearchCriteria"
OnTextChanged="txtSearchCriteria_TextChanged" runat="server"
AutoPostBack=True></asp:textbox></input>&nbsp;&nbsp;
.......
.......
</form>

Here's the procedure code:

Sub txtSearchCriteria_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs)
Try
FindArticles()
blnSearch = True
Catch ex As Exception
Throw ex
End Try
End Sub


Any suggestions would be greatly appreciated!
Pat
 
H

Hermit Dave

asp.net form doesnot automatically submit on key press enter key.
change event is fired on onLostFocus and causes the focus to move from
current control to the next control then it fires the changed event then.

hth

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
K

Karl

TextChanged is fired when the control loses focus...hitting enter doesn't
change focus..hitting tab moves the cursor to the next item, thus it loses
focus...

karl
 
P

PD

So how could I get the enter key to kick off an event on the code
behind? The function I'm trying to get to work is a search page. When
user's type in a search filter and hit 'Enter' I would like that to
trigger the code that returns the result data to the page. Thoughts?
Thanks again!
 
P

PD

Found a solution... Added onkeypress="return(submitForm());" to the
asp:text control. SubmitForm code..

function submitForm()
{
if (event.keyCode == 13)
{
frmArticle.submit();
}
}
</script>

Then when return key is pressed, the form submits. Appears to work
fine so far.
 
H

Hermit Dave

well you could manually trap the enter key using javascript and call same
clientside code as the onLostFocus

but its not a clean way to do it.. and i just disable enter key.. ie do
nothing if enter key is pressed.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top