Solved

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

Posted on 2009-07-13
12
662 Views
Last Modified: 2012-05-07
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.
0
Comment
Question by:pythonV
  • 6
  • 6
12 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 24846787
Can you not enclose the textbox and button inside a form?
0
 

Author Comment

by:pythonV
ID: 24847215
I'm not sure what you mean exactly, however they have to be in a form.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 24847220
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
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.

 

Author Comment

by:pythonV
ID: 24847274
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 24847301
What server side code are you talking about?
0
 

Author Comment

by:pythonV
ID: 24847308
i have some vb code in the Click event of the button.

I'm using ASP.NET.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 24847315
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
 

Author Comment

by:pythonV
ID: 24847331
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
 
LVL 36

Expert Comment

by:Zyloch
ID: 24847342
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
 

Author Comment

by:pythonV
ID: 24847362
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
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 24847385
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
 

Author Comment

by:pythonV
ID: 24892822
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question