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.

Thanks,

Pythonv.
pythonVAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZylochCommented:
Can you not enclose the textbox and button inside a form?
0
pythonVAuthor Commented:
I'm not sure what you mean exactly, however they have to be in a form.
0
ZylochCommented:
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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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.

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

Open in new window

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

I'm using ASP.NET.
0
ZylochCommented:
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?
0
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.
0
ZylochCommented:
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.
0
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.
0
ZylochCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

Thanks,

Pythonv.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.