Solved

ASP.NET Default Button using Mobile Internet Explorer

Posted on 2009-07-08
11
593 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:pythonV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 3

Expert Comment

by:Kelevra
ID: 24805340
Hi,
Does this button, trigger client or server side logic?
0
 

Author Comment

by:pythonV
ID: 24837240
thanks for the reponse, It triggers server side logic.
0
 

Author Comment

by:pythonV
ID: 24837818
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pythonV
ID: 24838161
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
 
LVL 3

Expert Comment

by:Kelevra
ID: 24839316
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
 

Author Comment

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

Author Comment

by:pythonV
ID: 24846528
I also tried it as " if (e.which == 13) {" but same result.
0
 

Author Comment

by:pythonV
ID: 24847638
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
 
LVL 3

Expert Comment

by:Kelevra
ID: 24849185
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
 
LVL 3

Accepted Solution

by:
Kelevra earned 500 total points
ID: 24855357
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
 

Author Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

730 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