problem with defaultbutton cross browser

Discussion in 'ASP .Net' started by PNR, Nov 4, 2009.

  1. PNR

    PNR Guest

    I have a problem making a deafultbutton that works cross browser, I tried
    setting a defaultbutton on a panel, but that diden't work in Firefox. I have
    also tried to use som java-script:
    I have added a "onkeydown" event to the textbox that shall belon to a
    certain button

    <script type="text/javascript" language="JavaScript1.2">

    function defaultButtonFunktion(evt, btn) {
    var keyCode = evt.which ? evt.which : evt.keyCode;
    if (keyCode == 13) {
    evt.returnValue=false;
    evt.cancel = true;
    btn.click();
    }
    }
    </script>

    This also dossen't work in FireFox.

    What do I do?

    Thanks in adavance
     
    PNR, Nov 4, 2009
    #1
    1. Advertising

  2. On Nov 4, 8:36 am, PNR <> wrote:
    > I have a problem making a deafultbutton that works cross browser, I tried
    > setting a defaultbutton on a panel, but that diden't work in Firefox. I have
    > also tried to use som java-script:
    > I have added a "onkeydown" event to the textbox that shall belon to a
    > certain button
    >
    > <script type="text/javascript" language="JavaScript1.2">
    >
    >         function defaultButtonFunktion(evt, btn) {
    >             var keyCode = evt.which ? evt.which : evt.keyCode;
    >             if (keyCode == 13) {
    >                 evt.returnValue=false;
    >                 evt.cancel = true;
    >                 btn.click();
    >             }
    >         }
    >     </script>  
    >
    > This also dossen't work in FireFox.
    >
    > What do I do?
    >
    > Thanks in adavance


    Looks like your code is correct. At least, for me it works in IE and
    FF

    <%@ Page Language="vb" AutoEventWireup="false"
    CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

    <!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></title>

    <script type="text/javascript" language="JavaScript1.2">


    function defaultButtonFunktion(evt, btn) {
    var keyCode = evt.which ? evt.which : evt.keyCode;
    if (keyCode == 13) {
    evt.returnValue = false;
    evt.cancel = true;
    btn.click();
    }
    }
    </script>

    </head>
    <body onkeydown="defaultButtonFunktion(event,document.getElementById('<
    %=Button2.ClientID %>'))">
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Button ID="Button2" runat="server" Text="Button" />
    <asp:Button ID="Button3" runat="server" Text="Button" />
    </div>
    </form>
    </body>
    </html>
     
    Alexey Smirnov, Nov 4, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    11,132
    TonyDong
    Jun 8, 2007
  2. Yuan Ren[MSFT]
    Replies:
    2
    Views:
    1,810
    Yuan Ren[MSFT]
    Feb 7, 2006
  3. =?Utf-8?B?VHlsZXIgQ2FydmVy?=

    Programmatic Use of DefaultButton Doesn't Work in FireFox

    =?Utf-8?B?VHlsZXIgQ2FydmVy?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    3,837
    Yuan Ren[MSFT]
    Mar 15, 2006
  4. Evert Wiesenekker
    Replies:
    0
    Views:
    574
    Evert Wiesenekker
    May 3, 2006
  5. Evert Wiesenekker
    Replies:
    0
    Views:
    454
    Evert Wiesenekker
    May 3, 2006
Loading...

Share This Page