How do I invoke Button click from textbox in Pocket Internet Explorer using Javascript and ASP.NET

Hello experts,

I am using ASP.NET and VB to create a webpage which has a textbox and a button. Once some text is entered in the textbox and the enter key is pressed I want the Button click to be invoked so that the server-side code is executed.

I tried to use the default button on an html panel but that didn't work.

Now I tried the following Javascript which works fine in IE6 on a PC:

<asp:TextBox ID="TextBox1" runat="server" onkeydown="if (event.keyCode == 13){document.getElementById('Button1').click();return false;}else{return true;}"></asp:TextBox></div>

However, the "onkeydown" html element is not supported in Pocket Internet Explorer HTML elements.

Any ideas how i can work around this?

I need a button click to be invoked when a user presses the enter key on a textbox.


Who is Participating?
ZylochConnect With a Mentor Commented:
Ok, let's take a step back. If this version of IE really does not support the keypress event... first, see if it support keydown and/or keyup. You could try to attach your code to those. If not, then you shouldn't be thinking about doing some script when the enter key is hit, since clearly your browser cannot handle those events. You should be thinking of alternatives. The best alternative is to attach your code to the form's onsubmit event, however that is done in VB. Even if it is server-side code, there is no reason I see that it cannot be handled in conjunction with your form submit code.
Can you not enclose the textbox and button inside a form?
pythonVAuthor Commented:
I'm not sure what you mean exactly, however they have to be in a form.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

No, I mean if you surround your specific text field and make your button a submit button, then pressing enter on the textfield would automatically submit your form and you don't need any logic on the button. You could have it call a JavaScript function in onsubmit.
pythonVAuthor Commented:
when i press enter, the form is submitted, however the server-side code behind the button click is not executed.

at the moment im looking for some javascript.
So far I found that some methods of js are not supported in Pocket IE.

Now im trying out jquery but so far no luck.

Any idea why the below code does not work?
again the form is submitted but server side code in button click event is not executed.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
  <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
    $("TextBox1").keypress(function (e) {
      if (e.keycode == 13) {
        return false;
      } else {
        return true;
  <form id="form1" runat="server">
      <asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>
    <asp:TextBox ID="TextBox1" runat="server" /></div>

Open in new window

What server side code are you talking about?
pythonVAuthor Commented:
i have some vb code in the Click event of the button.

I'm using ASP.NET.
I'm not very familiar with ASP.NET, but can you not have this code run after the form submits? Or is it some sort of validation code?
pythonVAuthor Commented:
to test out the JS im using this code

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Button1.Text = "Clicked"
  End Sub

When the Button is clicked its text changes.

That line of code is not executed when i hit the enter button while focus is on the textbox.
You can do the same JS to change the button's text on the form. There's probably a VB way to do it, but there's definitely a JavaScript way to do it.
pythonVAuthor Commented:
IF using that text change code just for testing, the code I want to execute in my page in more complex and can't be done in js.

The thing I need to do with JS is invoke the Button Click when hitting the enter key on the text box.
pythonVAuthor Commented:
Thanks for the info zyloch,

As it turns out, Pocket IE is pretty much useless in terms of JS so i'm going to have to find a server-side alternative.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.