ASP.NET Default Button using Mobile Internet Explorer

Hello Experts,

I need to use a Default Button on an ASP.NET (VB) web page. Using Internet Explorer on a PC it works fine, however, I need to use this on a Windows Mobile 5 device.

I tried the default Button of a panel however it doesn't work.

I  found out that I would have to use some kind of Javascript.

Any Ideas??
thanks.
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.

KelevraCommented:
Hi,
Does this button, trigger client or server side logic?
0
pythonVAuthor Commented:
thanks for the reponse, It triggers server side logic.
0
pythonVAuthor Commented:
Rather than a default button i am trying to use client side javascript to invoke the button click.

I am trying this code however it does not seem to work:

<asp:TextBox ID="txtMyTextBox" runat="server" onkeydown="document.all(getElementById('btnIwantClickedt')).click()"></asp:TextBox><br /><br />


any ideas why thid does not work?

thanks.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

pythonVAuthor Commented:
I tried the following JS which works fine in IE8 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
KelevraCommented:
Ok, That's easy:

Try using the JQuery Javascript Library, that contains lots of nice ready to use functions.

In this example below, the text box is bind to almost all keypress.

But you can easly adapt it to just the enter key.


$("input") here you write the element you want to bind to the event (here keypress event)
$(".myClass") if you want to target an element using the class here is how to do ( adding a point before the class's name)
$("#myID") SAme with an ID, but instead of a (.) you use a (#).

and this is the equivalent to the Document.ready javascript function for the jQuery one.

Again all is explain here:  http://docs.jquery.com/Tutorials

 $(document).ready(function(){

logic here

  });

Hope this help.

p.s, Don't hesitate to check the Jquery web site for more...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("input").keypress(function (e) {
      if (e.which == 32 || (65 <= e.which && e.which <= 65 + 25)
                        || (97 <= e.which && e.which <= 97 + 25)) {
        var c = String.fromCharCode(e.which);
        $("p").append($("<span/>"))
              .children(":last")
              .append(document.createTextNode(c));
      } else if (e.which == 8) {
        // backspace in IE only be on keydown
        $("p").children(":last").remove();
      }
      $("div").text(e.which);
    });
 
  });
  </script>
  <style>
  input { margin:10px; }
  p { color:blue; margin:10px; font-size:18px; }
  p.hilite { background:yellow; }
  div { color:red; }
  </style>
</head>
<body>
  <input type="text" />
  <p>Add text - </p>
  <div></div>
</body>
</html>

Open in new window

0
pythonVAuthor Commented:
Thanks for the response, its close to what i need.

I'm trying the following code but the function does not seem to be working working.

what am i doing wrong?

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 {
        // backspace in IE only be on keydown
        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
pythonVAuthor Commented:
I also tried it as " if (e.which == 13) {" but same result.
0
pythonVAuthor Commented:
I took the code you gave me, saved it as html document and hosted on my machine.

Opened it from other PCs running IE6 or later it worked well,

However I tried it on a Pocket IE using Device Emulator and it still didn't work. I type into the textbox and nothing happens.

I'm starting to think that no Javascript that can give me what I want will work on Pocket IE.

Should I be looking for alternate solutions?
0
KelevraCommented:
Try that, it might be better,

although, I am not sure about Pocket IE.

I will give it a good look.




var event = document.getElementById('Button1').click();
 
 
 
 
<%@ 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(){
    
         $("#button").click(function () {
            //action of button1 here
         });
 
 
    $("TextBox1").keypress(function (e) {
      if (e.keycode == 13) {
         $("#button1").trigger('click');
        return false;
      } else {
        // backspace in IE only be on keydown
        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
KelevraCommented:
As I suspected,
Pocket Internet Explorer (PIE) is the least functional browser (big
surprise).  It won't even begin to run the jQuery test suite
(www.jQuery.com/test).  From what I know PIE is a basic mobile browser
that has only recently added basic AJAX, DOM, and XMLDOM support.  I
haven't gotten further with testing, because I don't yet know why the
test won't load.

PIE does not support the Java run time or JavaScript. It does support JSCRIPT, a subset of JavaScript, created by Microsoft.

that's it for now.
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, i was beginning to discover the lack of javascript support in PIE.

I checked out the JSCRIPT and the available functionality is very limited.

This is extremely annoying, I have to play around with strings and postback to accept an input in ASP.NET rather than using a simple JS function which would do the job better.
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
.NET Programming

From novice to tech pro — start learning today.