Solved

ASP.NET Default Button using Mobile Internet Explorer

Posted on 2009-07-08
11
563 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
  • 7
  • 4
11 Comments
 
LVL 3

Expert Comment

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

Author Comment

by:pythonV
Comment Utility
thanks for the reponse, It triggers server side logic.
0
 

Author Comment

by:pythonV
Comment Utility
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
 

Author Comment

by:pythonV
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:pythonV
Comment Utility
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
Comment Utility
I also tried it as " if (e.which == 13) {" but same result.
0
 

Author Comment

by:pythonV
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

763 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

8 Experts available now in Live!

Get 1:1 Help Now