Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

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.
0
pythonV
Asked:
pythonV
  • 6
  • 6
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now