zoukankan      html  css  js  c++  java
  • simulate button click

    Origin source:http://www.issociate.de/board/index.php?t=msg&rid=0&th=66055&goto=330723#msg_330723
    Also, see ALWAYS ON TOP LINKS MENU http://sivamdesign.com/scripts/navigate.html


    I have message entry screen that's causing me a bit of an issue. At the
    moment, there are 2 buttons, one is used to send message
    to another user
    (btnSend) and another is used to send messages to all users (btnSendAll).

    When user hits enter, I also simulate the effect of clicking button
    (btnSend). However, what I found btnSend doesn't fire (unless I click on the
    button).

    The postback function I call is as follows:
    function __doPostBack(eventTarget, eventArgument)
    {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
    {
    theform = document.forms["Form1"];
    }
    else
    {
    theform = document.Form1;
    }
    theform.submit();
    }

    The script used to cause a postback is as follows:
    <script language="javascript">
    var mykey;
    var posted=false;

    if (window.Event){
    document.captureEvents(Event.KEYDOWN);
    }

    document.onkeydown = myKeyDown;

    function myKeyDown(e){

    if (window.Event){
    mykey = e.which;
    }
    else{
    mykey = event.keyCode;
    }
    //alert(mykey);
    if ((mykey==13) && (posted==false))
    {
    posted=true;
    __doPostBack('btnSend:','onclick');
    }

    }
    </script>


    I think my problem is either not specifying eventTarget or eventArgument
    correctly. Can someone please give a pointer on this.

    Many thanx
    RE: postback simulating button click [message #222721 ] Mi, 13 Oktober 2004 10:35
    EthemAzun  
    Hi CW,

    I don't understand the requirement to catch the postback event on the client
    side. Anyway, what you can try is to "click" on the button like this inside
    the myKeyDown manually:
    bntSend.click();

    Define your button as a submit button, then it will automatically postback
    and you don't have to catch the postback event. In any case, why don't you
    use an asp:button?

    Hope this helps,

    Ethem

    "CW" wrote:

    > I have message entry screen that's causing me a bit of an issue. At the
    > moment, there are 2 buttons, one is used to send message to another user
    > (btnSend) and another is used to send messages to all users (btnSendAll).
    >
    > When user hits enter, I also simulate the effect of clicking button
    > (btnSend). However, what I found btnSend doesn't fire (unless I click on the
    > button).
    >
    > The postback function I call is as follows:
    > function __doPostBack(eventTarget, eventArgument)
    > {
    > var theform;
    > if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
    > {
    > theform = document.forms["Form1"];
    > }
    > else
    > {
    > theform = document.Form1;
    > }
    > theform.submit();
    > }
    >
    > The script used to cause a postback is as follows:
    > <script language="javascript">
    > var mykey;
    > var posted=false;
    >
    > if (window.Event){
    > document.captureEvents(Event.KEYDOWN);
    > }
    >
    > document.onkeydown = myKeyDown;
    >
    > function myKeyDown(e){
    >
    > if (window.Event){
    > mykey = e.which;
    > }
    > else{
    > mykey = event.keyCode;
    > }
    > //alert(mykey);
    > if ((mykey==13) && (posted==false))
    > {
    > posted=true;
    > __doPostBack('btnSend:','onclick');
    > }
    >
    > }
    > </script>
    >
    >
    > I think my problem is either not specifying eventTarget or eventArgument
    > correctly. Can someone please give a pointer on this.
    >
    > Many thanx
    >
    >
    >
    RE: postback simulating button click [message #222742 ] Mi, 13 Oktober 2004 12:00
    v-schang  
    Hi CW,

    Are you wanting to provide a function just like the "Default Button" in
    winform application? If so, generally we can just add the "onkeydown"
    script for the entryfield where the user will enter messages before he
    submit.
    Here are some former threads in the newsgroup discussing on this qustion,
    you may have a look:

    http://groups.google.com/groups?hl=en&lr=&threadm=25ZlQYfSEH A.2988%40cpmsftn
    gxa10.phx.gbl&rnum=6&prev=/groups%3Fq%3Dasp.net%2Bdefault%2B button%2Bsteven%
    2Bcheng%26hl%3Den

    http://groups.google.com/groups?hl=en&lr=&threadm=x8Tmqg83DH A.1992%40cpmsftn
    gxa07.phx.gbl&rnum=8&prev=/groups%3Fq%3Dasp.net%2Bdefault%2B button%2Bsteven%
    2Bcheng%26hl%3Den

    Hope helps. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Re: postback simulating button click [message #238655 ] Mi, 13 Oktober 2004 14:13
    CW  
    They are asp.net buttons actually.

    I need to catch enter so that it would have the same behaviour on different
    browsers, not just IE.

    btnSend.click works on IE, but does not work on Netscape or Mozilla.

    Thanx


    "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    >
    > Hi CW,
    >
    > I don't understand the requirement to catch the postback event on the
    > client
    > side. Anyway, what you can try is to "click" on the button like this
    > inside
    > the myKeyDown manually:
    > bntSend.click();
    >
    > Define your button as a submit button, then it will automatically postback
    > and you don't have to catch the postback event. In any case, why don't you
    > use an asp:button?
    >
    > Hope this helps,
    >
    > Ethem
    >
    > "CW" wrote:
    >
    >> I have message entry screen that's causing me a bit of an issue. At the
    >> moment, there are 2 buttons, one is used to send message to another user
    >> (btnSend) and another is used to send messages to all users (btnSendAll).
    >>
    >> When user hits enter, I also simulate the effect of clicking button
    >> (btnSend). However, what I found btnSend doesn't fire (unless I click on
    >> the
    >> button).
    >>
    >> The postback function I call is as follows:
    >> function __doPostBack(eventTarget, eventArgument)
    >> {
    >> var theform;
    >> if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
    >> {
    >> theform = document.forms["Form1"];
    >> }
    >> else
    >> {
    >> theform = document.Form1;
    >> }
    >> theform.submit();
    >> }
    >>
    >> The script used to cause a postback is as follows:
    >> <script language="javascript">
    >> var mykey;
    >> var posted=false;
    >>
    >> if (window.Event){
    >> document.captureEvents(Event.KEYDOWN);
    >> }
    >>
    >> document.onkeydown = myKeyDown;
    >>
    >> function myKeyDown(e){
    >>
    >> if (window.Event){
    >> mykey = e.which;
    >> }
    >> else{
    >> mykey = event.keyCode;
    >> }
    >> //alert(mykey);
    >> if ((mykey==13) && (posted==false))
    >> {
    >> posted=true;
    >> __doPostBack('btnSend:','onclick');
    >> }
    >>
    >> }
    >> </script>
    >>
    >>
    >> I think my problem is either not specifying eventTarget or eventArgument
    >> correctly. Can someone please give a pointer on this.
    >>
    >> Many thanx
    >>
    >>
    >>
    Re: postback simulating button click [message #247764 ] Mi, 13 Oktober 2004 16:09
    EthemAzun  
    Hi,

    I have Netscape 7.1 and the following does work (which is simply the
    button.click() added to your code.). Are you sure that you are not doing
    something wrong other than this? The aspnet button will be rendered as a
    simple submit button.

    <HTML>
    <HEAD>
    <title>Netscape</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    <script language="javascript">
    var mykey;
    var posted=false;
    if (window.Event){
    document.captureEvents(Event.KEYDOWN);
    }
    document.onkeydown = myKeyDown;
    function myKeyDown(e){
    if (window.Event){
    mykey = e.which;
    }
    else{
    mykey = event.keyCode;
    }
    //alert(mykey);
    if ((mykey==13) && (posted==false))
    {
    posted=true;
    this.Form1.butTest.click();
    }
    }
    </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
    absolute; TOP: 32px" runat="server" Text="Button" Width="96px"></asp:Button>
    </form>
    </body>
    </HTML>

    "CW" wrote:

    > They are asp.net buttons actually.
    >
    > I need to catch enter so that it would have the same behaviour on different
    > browsers, not just IE.
    >
    > btnSend.click works on IE, but does not work on Netscape or Mozilla.
    >
    > Thanx
    >
    >
    > "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    > >
    > > Hi CW,
    > >
    > > I don't understand the requirement to catch the postback event on the
    > > client
    > > side. Anyway, what you can try is to "click" on the button like this
    > > inside
    > > the myKeyDown manually:
    > > bntSend.click();
    > >
    > > Define your button as a submit button, then it will automatically postback
    > > and you don't have to catch the postback event. In any case, why don't you
    > > use an asp:button?
    > >
    > > Hope this helps,
    > >
    > > Ethem
    > >
    > > "CW" wrote:
    > >
    > >> I have message entry screen that's causing me a bit of an issue. At the
    > >> moment, there are 2 buttons, one is used to send message to another user
    > >> (btnSend) and another is used to send messages to all users (btnSendAll).
    > >>
    > >> When user hits enter, I also simulate the effect of clicking button
    > >> (btnSend). However, what I found btnSend doesn't fire (unless I click on
    > >> the
    > >> button).
    > >>
    > >> The postback function I call is as follows:
    > >> function __doPostBack(eventTarget, eventArgument)
    > >> {
    > >> var theform;
    > >> if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
    > >> {
    > >> theform = document.forms["Form1"];
    > >> }
    > >> else
    > >> {
    > >> theform = document.Form1;
    > >> }
    > >> theform.submit();
    > >> }
    > >>
    > >> The script used to cause a postback is as follows:
    > >> <script language="javascript">
    > >> var mykey;
    > >> var posted=false;
    > >>
    > >> if (window.Event){
    > >> document.captureEvents(Event.KEYDOWN);
    > >> }
    > >>
    > >> document.onkeydown = myKeyDown;
    > >>
    > >> function myKeyDown(e){
    > >>
    > >> if (window.Event){
    > >> mykey = e.which;
    > >> }
    > >> else{
    > >> mykey = event.keyCode;
    > >> }
    > >> //alert(mykey);
    > >> if ((mykey==13) && (posted==false))
    > >> {
    > >> posted=true;
    > >> __doPostBack('btnSend:','onclick');
    > >> }
    > >>
    > >> }
    > >> </script>
    > >>
    > >>
    > >> I think my problem is either not specifying eventTarget or eventArgument
    > >> correctly. Can someone please give a pointer on this.
    > >>
    > >> Many thanx
    > >>
    > >>
    > >>
    >
    >
    >
    Re: postback simulating button click [message #259213 ] Mi, 13 Oktober 2004 16:50
    CW  
    I think latest NN 7.x is fine. But the same javascript does not seem to fire
    postback when run int NN 6.x and NN 4.x and Mozilla .9x.

    Form1.btnSend.click() does not seem to be recognizable to them.

    "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    news:0AFA3531-F547-4905-A747-ED8302DE9D53 [at] microsoft.com...
    >
    > Hi,
    >
    > I have Netscape 7.1 and the following does work (which is simply the
    > button.click() added to your code.). Are you sure that you are not doing
    > something wrong other than this? The aspnet button will be rendered as a
    > simple submit button.
    >
    > <HTML>
    > <HEAD>
    > <title>Netscape</title>
    > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > <meta name="CODE_LANGUAGE" Content="C#">
    > <meta name="vs_defaultClientScript" content="JavaScript">
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    > <script language="javascript">
    > var mykey;
    > var posted=false;
    > if (window.Event){
    > document.captureEvents(Event.KEYDOWN);
    > }
    > document.onkeydown = myKeyDown;
    > function myKeyDown(e){
    > if (window.Event){
    > mykey = e.which;
    > }
    > else{
    > mykey = event.keyCode;
    > }
    > //alert(mykey);
    > if ((mykey==13) && (posted==false))
    > {
    > posted=true;
    > this.Form1.butTest.click();
    > }
    > }
    > </script>
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > <asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
    > absolute; TOP: 32px" runat="server" Text="Button"
    > Width="96px"></asp:Button>
    > </form>
    > </body>
    > </HTML>
    >
    > "CW" wrote:
    >
    >> They are asp.net buttons actually.
    >>
    >> I need to catch enter so that it would have the same behaviour on
    >> different
    >> browsers, not just IE.
    >>
    >> btnSend.click works on IE, but does not work on Netscape or Mozilla.
    >>
    >> Thanx
    >>
    >>
    >> "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    >> news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    >> >
    >> > Hi CW,
    >> >
    >> > I don't understand the requirement to catch the postback event on the
    >> > client
    >> > side. Anyway, what you can try is to "click" on the button like this
    >> > inside
    >> > the myKeyDown manually:
    >> > bntSend.click();
    >> >
    >> > Define your button as a submit button, then it will automatically
    >> > postback
    >> > and you don't have to catch the postback event. In any case, why don't
    >> > you
    >> > use an asp:button?
    >> >
    >> > Hope this helps,
    >> >
    >> > Ethem
    >> >
    >> > "CW" wrote:
    >> >
    >> >> I have message entry screen that's causing me a bit of an issue. At
    >> >> the
    >> >> moment, there are 2 buttons, one is used to send message to another
    >> >> user
    >> >> (btnSend) and another is used to send messages to all users
    >> >> (btnSendAll).
    >> >>
    >> >> When user hits enter, I also simulate the effect of clicking button
    >> >> (btnSend). However, what I found btnSend doesn't fire (unless I click
    >> >> on
    >> >> the
    >> >> button).
    >> >>
    >> >> The postback function I call is as follows:
    >> >> function __doPostBack(eventTarget, eventArgument)
    >> >> {
    >> >> var theform;
    >> >> if (window.navigator.appName.toLowerCase().indexOf("netscape")
    >> >> > -1)
    >> >> {
    >> >> theform = document.forms["Form1"];
    >> >> }
    >> >> else
    >> >> {
    >> >> theform = document.Form1;
    >> >> }
    >> >> theform.submit();
    >> >> }
    >> >>
    >> >> The script used to cause a postback is as follows:
    >> >> <script language="javascript">
    >> >> var mykey;
    >> >> var posted=false;
    >> >>
    >> >> if (window.Event){
    >> >> document.captureEvents(Event.KEYDOWN);
    >> >> }
    >> >>
    >> >> document.onkeydown = myKeyDown;
    >> >>
    >> >> function myKeyDown(e){
    >> >>
    >> >> if (window.Event){
    >> >> mykey = e.which;
    >> >> }
    >> >> else{
    >> >> mykey = event.keyCode;
    >> >> }
    >> >> //alert(mykey);
    >> >> if ((mykey==13) && (posted==false))
    >> >> {
    >> >> posted=true;
    >> >> __doPostBack('btnSend:','onclick');
    >> >> }
    >> >>
    >> >> }
    >> >> </script>
    >> >>
    >> >>
    >> >> I think my problem is either not specifying eventTarget or
    >> >> eventArgument
    >> >> correctly. Can someone please give a pointer on this.
    >> >>
    >> >> Many thanx
    >> >>
    >> >>
    >> >>
    >>
    >>
    >>
    Re: postback simulating button click [message #259223 ] Mi, 13 Oktober 2004 17:15
    JeremyDavis  
    How about
    document.getElementById('btnSend').click();

    "CW" wrote:

    > I think latest NN 7.x is fine. But the same javascript does not seem to fire
    > postback when run int NN 6.x and NN 4.x and Mozilla .9x.
    >
    > Form1.btnSend.click() does not seem to be recognizable to them.
    >
    > "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > news:0AFA3531-F547-4905-A747-ED8302DE9D53 [at] microsoft.com...
    > >
    > > Hi,
    > >
    > > I have Netscape 7.1 and the following does work (which is simply the
    > > button.click() added to your code.). Are you sure that you are not doing
    > > something wrong other than this? The aspnet button will be rendered as a
    > > simple submit button.
    > >
    > > <HTML>
    > > <HEAD>
    > > <title>Netscape</title>
    > > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > > <meta name="CODE_LANGUAGE" Content="C#">
    > > <meta name="vs_defaultClientScript" content="JavaScript">
    > > <meta name="vs_targetSchema"
    > > content="http://schemas.microsoft.com/intellisense/ie5">
    > > <script language="javascript">
    > > var mykey;
    > > var posted=false;
    > > if (window.Event){
    > > document.captureEvents(Event.KEYDOWN);
    > > }
    > > document.onkeydown = myKeyDown;
    > > function myKeyDown(e){
    > > if (window.Event){
    > > mykey = e.which;
    > > }
    > > else{
    > > mykey = event.keyCode;
    > > }
    > > //alert(mykey);
    > > if ((mykey==13) && (posted==false))
    > > {
    > > posted=true;
    > > this.Form1.butTest.click();
    > > }
    > > }
    > > </script>
    > > </HEAD>
    > > <body MS_POSITIONING="GridLayout">
    > > <form id="Form1" method="post" runat="server">
    > > <asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
    > > absolute; TOP: 32px" runat="server" Text="Button"
    > > Width="96px"></asp:Button>
    > > </form>
    > > </body>
    > > </HTML>
    > >
    > > "CW" wrote:
    > >
    > >> They are asp.net buttons actually.
    > >>
    > >> I need to catch enter so that it would have the same behaviour on
    > >> different
    > >> browsers, not just IE.
    > >>
    > >> btnSend.click works on IE, but does not work on Netscape or Mozilla.
    > >>
    > >> Thanx
    > >>
    > >>
    > >> "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > >> news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    > >> >
    > >> > Hi CW,
    > >> >
    > >> > I don't understand the requirement to catch the postback event on the
    > >> > client
    > >> > side. Anyway, what you can try is to "click" on the button like this
    > >> > inside
    > >> > the myKeyDown manually:
    > >> > bntSend.click();
    > >> >
    > >> > Define your button as a submit button, then it will automatically
    > >> > postback
    > >> > and you don't have to catch the postback event. In any case, why don't
    > >> > you
    > >> > use an asp:button?
    > >> >
    > >> > Hope this helps,
    > >> >
    > >> > Ethem
    > >> >
    > >> > "CW" wrote:
    > >> >
    > >> >> I have message entry screen that's causing me a bit of an issue. At
    > >> >> the
    > >> >> moment, there are 2 buttons, one is used to send message to another
    > >> >> user
    > >> >> (btnSend) and another is used to send messages to all users
    > >> >> (btnSendAll).
    > >> >>
    > >> >> When user hits enter, I also simulate the effect of clicking button
    > >> >> (btnSend). However, what I found btnSend doesn't fire (unless I click
    > >> >> on
    > >> >> the
    > >> >> button).
    > >> >>
    > >> >> The postback function I call is as follows:
    > >> >> function __doPostBack(eventTarget, eventArgument)
    > >> >> {
    > >> >> var theform;
    > >> >> if (window.navigator.appName.toLowerCase().indexOf("netscape")
    > >> >> > -1)
    > >> >> {
    > >> >> theform = document.forms["Form1"];
    > >> >> }
    > >> >> else
    > >> >> {
    > >> >> theform = document.Form1;
    > >> >> }
    > >> >> theform.submit();
    > >> >> }
    > >> >>
    > >> >> The script used to cause a postback is as follows:
    > >> >> <script language="javascript">
    > >> >> var mykey;
    > >> >> var posted=false;
    > >> >>
    > >> >> if (window.Event){
    > >> >> document.captureEvents(Event.KEYDOWN);
    > >> >> }
    > >> >>
    > >> >> document.onkeydown = myKeyDown;
    > >> >>
    > >> >> function myKeyDown(e){
    > >> >>
    > >> >> if (window.Event){
    > >> >> mykey = e.which;
    > >> >> }
    > >> >> else{
    > >> >> mykey = event.keyCode;
    > >> >> }
    > >> >> //alert(mykey);
    > >> >> if ((mykey==13) && (posted==false))
    > >> >> {
    > >> >> posted=true;
    > >> >> __doPostBack('btnSend:','onclick');
    > >> >> }
    > >> >>
    > >> >> }
    > >> >> </script>
    > >> >>
    > >> >>
    > >> >> I think my problem is either not specifying eventTarget or
    > >> >> eventArgument
    > >> >> correctly. Can someone please give a pointer on this.
    > >> >>
    > >> >> Many thanx
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>
    >
    >
    >
    Re: postback simulating button click [message #259250 ] Mi, 13 Oktober 2004 18:00
    EthemAzun  
    or
    document.forms["Form1"].bntSend.click()
    or even
    document.forms[0].bntSend.click() ?

    it quite weird if they don't work either. Can you take a look at your html
    output to see the id of the button if the ones above don't work?

    "Jeremy Davis" wrote:

    > How about
    > document.getElementById('btnSend').click();
    >
    > "CW" wrote:
    >
    > > I think latest NN 7.x is fine. But the same javascript does not seem to fire
    > > postback when run int NN 6.x and NN 4.x and Mozilla .9x.
    > >
    > > Form1.btnSend.click() does not seem to be recognizable to them.
    > >
    > > "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > > news:0AFA3531-F547-4905-A747-ED8302DE9D53 [at] microsoft.com...
    > > >
    > > > Hi,
    > > >
    > > > I have Netscape 7.1 and the following does work (which is simply the
    > > > button.click() added to your code.). Are you sure that you are not doing
    > > > something wrong other than this? The aspnet button will be rendered as a
    > > > simple submit button.
    > > >
    > > > <HTML>
    > > > <HEAD>
    > > > <title>Netscape</title>
    > > > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > > > <meta name="CODE_LANGUAGE" Content="C#">
    > > > <meta name="vs_defaultClientScript" content="JavaScript">
    > > > <meta name="vs_targetSchema"
    > > > content="http://schemas.microsoft.com/intellisense/ie5">
    > > > <script language="javascript">
    > > > var mykey;
    > > > var posted=false;
    > > > if (window.Event){
    > > > document.captureEvents(Event.KEYDOWN);
    > > > }
    > > > document.onkeydown = myKeyDown;
    > > > function myKeyDown(e){
    > > > if (window.Event){
    > > > mykey = e.which;
    > > > }
    > > > else{
    > > > mykey = event.keyCode;
    > > > }
    > > > //alert(mykey);
    > > > if ((mykey==13) && (posted==false))
    > > > {
    > > > posted=true;
    > > > this.Form1.butTest.click();
    > > > }
    > > > }
    > > > </script>
    > > > </HEAD>
    > > > <body MS_POSITIONING="GridLayout">
    > > > <form id="Form1" method="post" runat="server">
    > > > <asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
    > > > absolute; TOP: 32px" runat="server" Text="Button"
    > > > Width="96px"></asp:Button>
    > > > </form>
    > > > </body>
    > > > </HTML>
    > > >
    > > > "CW" wrote:
    > > >
    > > >> They are asp.net buttons actually.
    > > >>
    > > >> I need to catch enter so that it would have the same behaviour on
    > > >> different
    > > >> browsers, not just IE.
    > > >>
    > > >> btnSend.click works on IE, but does not work on Netscape or Mozilla.
    > > >>
    > > >> Thanx
    > > >>
    > > >>
    > > >> "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > > >> news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    > > >> >
    > > >> > Hi CW,
    > > >> >
    > > >> > I don't understand the requirement to catch the postback event on the
    > > >> > client
    > > >> > side. Anyway, what you can try is to "click" on the button like this
    > > >> > inside
    > > >> > the myKeyDown manually:
    > > >> > bntSend.click();
    > > >> >
    > > >> > Define your button as a submit button, then it will automatically
    > > >> > postback
    > > >> > and you don't have to catch the postback event. In any case, why don't
    > > >> > you
    > > >> > use an asp:button?
    > > >> >
    > > >> > Hope this helps,
    > > >> >
    > > >> > Ethem
    > > >> >
    > > >> > "CW" wrote:
    > > >> >
    > > >> >> I have message entry screen that's causing me a bit of an issue. At
    > > >> >> the
    > > >> >> moment, there are 2 buttons, one is used to send message to another
    > > >> >> user
    > > >> >> (btnSend) and another is used to send messages to all users
    > > >> >> (btnSendAll).
    > > >> >>
    > > >> >> When user hits enter, I also simulate the effect of clicking button
    > > >> >> (btnSend). However, what I found btnSend doesn't fire (unless I click
    > > >> >> on
    > > >> >> the
    > > >> >> button).
    > > >> >>
    > > >> >> The postback function I call is as follows:
    > > >> >> function __doPostBack(eventTarget, eventArgument)
    > > >> >> {
    > > >> >> var theform;
    > > >> >> if (window.navigator.appName.toLowerCase().indexOf("netscape")
    > > >> >> > -1)
    > > >> >> {
    > > >> >> theform = document.forms["Form1"];
    > > >> >> }
    > > >> >> else
    > > >> >> {
    > > >> >> theform = document.Form1;
    > > >> >> }
    > > >> >> theform.submit();
    > > >> >> }
    > > >> >>
    > > >> >> The script used to cause a postback is as follows:
    > > >> >> <script language="javascript">
    > > >> >> var mykey;
    > > >> >> var posted=false;
    > > >> >>
    > > >> >> if (window.Event){
    > > >> >> document.captureEvents(Event.KEYDOWN);
    > > >> >> }
    > > >> >>
    > > >> >> document.onkeydown = myKeyDown;
    > > >> >>
    > > >> >> function myKeyDown(e){
    > > >> >>
    > > >> >> if (window.Event){
    > > >> >> mykey = e.which;
    > > >> >> }
    > > >> >> else{
    > > >> >> mykey = event.keyCode;
    > > >> >> }
    > > >> >> //alert(mykey);
    > > >> >> if ((mykey==13) && (posted==false))
    > > >> >> {
    > > >> >> posted=true;
    > > >> >> __doPostBack('btnSend:','onclick');
    > > >> >> }
    > > >> >>
    > > >> >> }
    > > >> >> </script>
    > > >> >>
    > > >> >>
    > > >> >> I think my problem is either not specifying eventTarget or
    > > >> >> eventArgument
    > > >> >> correctly. Can someone please give a pointer on this.
    > > >> >>
    > > >> >> Many thanx
    > > >> >>
    > > >> >>
    > > >> >>
    > > >>
    > > >>
    > > >>
    > >
    > >
    > >
    Re: postback simulating button click [message #283283 ] Mi, 13 Oktober 2004 23:35
    gh0st54  
    HI CW

    check into this
    on page load add this

    Page.RegisterHiddenField("__EVENTTARGET",this.<default button that you
    want>.ClientID);

    I use this on all pages with the javascript

    what happens is that by default the page button will be what you have
    set in < >

    when you post back the page will look at the __EVENTTARGET field to
    know with control trigged the post back



    "CW" <CW [at] nospam.com> wrote in message news:<OgFNwPTsEHA.3468 [at] TK2MSFTNGP15.phx.gbl>...
    > I think latest NN 7.x is fine. But the same javascript does not seem to fire
    > postback when run int NN 6.x and NN 4.x and Mozilla .9x.
    >
    > Form1.btnSend.click() does not seem to be recognizable to them.
    >
    > "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > news:0AFA3531-F547-4905-A747-ED8302DE9D53 [at] microsoft.com...
    > >
    > > Hi,
    > >
    > > I have Netscape 7.1 and the following does work (which is simply the
    > > button.click() added to your code.). Are you sure that you are not doing
    > > something wrong other than this? The aspnet button will be rendered as a
    > > simple submit button.
    > >
    > > <HTML>
    > > <HEAD>
    > > <title>Netscape</title>
    > > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > > <meta name="CODE_LANGUAGE" Content="C#">
    > > <meta name="vs_defaultClientScript" content="JavaScript">
    > > <meta name="vs_targetSchema"
    > > content="http://schemas.microsoft.com/intellisense/ie5">
    > > <script language="javascript">
    > > var mykey;
    > > var posted=false;
    > > if (window.Event){
    > > document.captureEvents(Event.KEYDOWN);
    > > }
    > > document.onkeydown = myKeyDown;
    > > function myKeyDown(e){
    > > if (window.Event){
    > > mykey = e.which;
    > > }
    > > else{
    > > mykey = event.keyCode;
    > > }
    > > //alert(mykey);
    > > if ((mykey==13) && (posted==false))
    > > {
    > > posted=true;
    > > this.Form1.butTest.click();
    > > }
    > > }
    > > </script>
    > > </HEAD>
    > > <body MS_POSITIONING="GridLayout">
    > > <form id="Form1" method="post" runat="server">
    > > <asp:Button id="butTest" style="Z-INDEX: 101; LEFT: 56px; POSITION:
    > > absolute; TOP: 32px" runat="server" Text="Button"
    > > Width="96px"></asp:Button>
    > > </form>
    > > </body>
    > > </HTML>
    > >
    > > "CW" wrote:
    > >
    > >> They are asp.net buttons actually.
    > >>
    > >> I need to catch enter so that it would have the same behaviour on
    > >> different
    > >> browsers, not just IE.
    > >>
    > >> btnSend.click works on IE, but does not work on Netscape or Mozilla.
    > >>
    > >> Thanx
    > >>
    > >>
    > >> "Ethem Azun" <EthemAzun [at] discussions.microsoft.com> wrote in message
    > >> news:6AD312AF-E412-423F-BF29-3C0A0D28FE60 [at] microsoft.com...
    > >> >
    > >> > Hi CW,
    > >> >
    > >> > I don't understand the requirement to catch the postback event on the
    > >> > client
    > >> > side. Anyway, what you can try is to "click" on the button like this
    > >> > inside
    > >> > the myKeyDown manually:
    > >> > bntSend.click();
    > >> >
    > >> > Define your button as a submit button, then it will automatically
    > >> > postback
    > >> > and you don't have to catch the postback event. In any case, why don't
    > >> > you
    > >> > use an asp:button?
    > >> >
    > >> > Hope this helps,
    > >> >
    > >> > Ethem
    > >> >
    > >> > "CW" wrote:
    > >> >
    > >> >> I have message entry screen that's causing me a bit of an issue. At
    > >> >> the
    > >> >> moment, there are 2 buttons, one is used to send message to another
    > >> >> user
    > >> >> (btnSend) and another is used to send messages to all users
    > >> >> (btnSendAll).
    > >> >>
    > >> >> When user hits enter, I also simulate the effect of clicking button
    > >> >> (btnSend). However, what I found btnSend doesn't fire (unless I click
    > >> >> on
    > >> >> the
    > >> >> button).
    > >> >>
    > >> >> The postback function I call is as follows:
    > >> >> function __doPostBack(eventTarget, eventArgument)
    > >> >> {
    > >> >> var theform;
    > >> >> if (window.navigator.appName.toLowerCase().indexOf("netscape")
    > >> >> > -1)
    > >> >> {
    > >> >> theform = document.forms["Form1"];
    > >> >> }
    > >> >> else
    > >> >> {
    > >> >> theform = document.Form1;
    > >> >> }
    > >> >> theform.submit();
    > >> >> }
    > >> >>
    > >> >> The script used to cause a postback is as follows:
    > >> >> <script language="javascript">
    > >> >> var mykey;
    > >> >> var posted=false;
    > >> >>
    > >> >> if (window.Event){
    > >> >> document.captureEvents(Event.KEYDOWN);
    > >> >> }
    > >> >>
    > >> >> document.onkeydown = myKeyDown;
    > >> >>
    > >> >> function myKeyDown(e){
    > >> >>
    > >> >> if (window.Event){
    > >> >> mykey = e.which;
    > >> >> }
    > >> >> else{
    > >> >> mykey = event.keyCode;
    > >> >> }
    > >> >> //alert(mykey);
    > >> >> if ((mykey==13) && (posted==false))
    > >> >> {
    > >> >> posted=true;
    > >> >> __doPostBack('btnSend:','onclick');
    > >> >> }
    > >> >>
    > >> >> }
    > >> >> </script>
    > >> >>
    > >> >>
    > >> >> I think my problem is either not specifying eventTarget or
    > >> >> eventArgument
    > >> >> correctly. Can someone please give a pointer on this.
    > >> >>
    > >> >> Many thanx
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>
    Re: postback simulating button click [message #324627 ] Do, 14 Oktober 2004 08:30
    v-schang  
    Hi CW,

    I think you can have a try on Jeremy's suggestion that use the
    document.getElementById method to locate the submit button object. I
    suspect that the problem is the submit button object is not located. The
    Submit button's click() simiulate method is implement in javascript1.0 so I
    think it should be support by netscape's early version.

    Also, here is another blog article maybe helpful:

    #Setting the default Button for a TextBox in ASP.NET
    http://weblogs.asp.net/rajbk/archive/2003/12/11/43023.aspx

    Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Re: postback simulating button click [message #330723 ] Do, 14 Oktober 2004 11:46
    CW  
    Hi everyone

    Thanks for all the suggestions and help. I managed to get it work after
    abandoning button.click() method.

    Eveutally, I was able to get button.click to work, however, I had to modify
    the code to use document.Form1.button.click()
    or document.forms["Form1"].button.click(). For some reason, not specifying
    document specifier causes the code not to run on NS browsers.


    "Steven Cheng[MSFT]" <v-schang [at] online.microsoft.com> wrote in message
    news:i9famdbsEHA.3920 [at] cpmsftngxa10.phx.gbl...
    > Hi CW,
    >
    > I think you can have a try on Jeremy's suggestion that use the
    > document.getElementById method to locate the submit button object. I
    > suspect that the problem is the submit button object is not located. The
    > Submit button's click() simiulate method is implement in javascript1.0 so
    > I
    > think it should be support by netscape's early version.
    >
    > Also, here is another blog article maybe helpful:
    >
    > #Setting the default Button for a TextBox in ASP.NET
    > http://weblogs.asp.net/rajbk/archive/2003/12/11/43023.aspx
    >
    > Thanks.
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    Re: postback simulating button click [message #340953 ] Fr, 15 Oktober 2004 02:36
    v-schang  
    HI CW,

    Thanks for your followup and I'm glad that you figured out the problem.
    Have a nice day!


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
  • 相关阅读:
    【GO】文件二进制读取
    【JAVA】IO FileInputStream 读取二进制文件
    【JAVA】Maven 常用命令
    【JAVA】java8 function apply() compose() andThen()
    【Java】Maven resoucese 目录文件获取
    【数据结构】线索二叉树
    【Java】Java中的null作为方法参数是被当做值传递
    【Python】《Effective Python》 读书笔记 (一)
    【Python】一个try/except/else/finally 组合使用的例子
    【数据结构】二叉树的创建与遍历
  • 原文地址:https://www.cnblogs.com/cy163/p/194617.html
Copyright © 2011-2022 走看看