Solved

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

Posted on 2009-07-13
12
658 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now