开发者

onclick event is not firing in Google Chrome

I am trying to fire the asp.net button click event from JavaScript. Its working fine in IE, but the same code is not working on Chrome, please help me. Here is the js code:

<script type= "text/javascript" language="javascript">
    var btnSave = document.getElementByI开发者_开发技巧d('btnSave');
    btnSave.click();
    alert("The changes are saved sucessfully!!"); 
</script>

Please help me


i hope i am not confusing you here... let me try to list out..

  • the button is an asp:button
  • the event click is triggered from javascript
  • an alert is placed after the click event is triggered

how will the control flow to the alert line at all? once the click event is triggered a post back process will start as it is an asp button...


EDIT

Since this is an ASP.NET button.. you need to resolve what will be client id.

your code sould be

<script type= "text/javascript" language="javascript">
var btnSave = document.getElementById('<%= btnSave.ClientID %>');
btnSave.click();
alert("The changes are saved sucessfully!!"); 


click() is an IE only method to support simulating an event in script. It does not work in mozilla (firefox) or webkit (chrome, safari).

Did you try actually clicking on the element with your mouse?


Try this

 <script type= "text/javascript" language="javascript">
    var btnSave = document.getElementById('<%= btnSave.ClientID %>');
    if(jQuery.browser.msie )
    {
        btnSave.click();
    }
    else
    {
        eval("<% =Page.ClientScript.GetPostBackEventReference(btnSave,string.Empty)%>");
    }
    alert("The changes are saved sucessfully!!"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜