views:

686

answers:

4

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.getElementById('btnSave');
    btnSave.click();
    alert("The changes are saved sucessfully!!"); 
</script>

Please help me

A: 

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!!"); 

yes,button id is btnSave. Its not not working on Chrome. Save button is inside update panel. Is it make any diference?
purnang.advant
@user48545:Thanks , i have changed the code, still its not working. Please comment the alert after the click(), and try on chrome, it not working
purnang.advant
A: 

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...

ZX12R
A: 

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?

plodder
@Angus Croll: Ok. I am explaining my senario, I have a save button on my page(.aspx).One time its clicked by mouse. and in some logic i need to do it by java script. My code,var btn = document.getElementById('<%= btnGetLastData.ClientID %>'); btn.click();Its not working on chrome, as you mentioned It does not work in mozilla (firefox) or webkit (chrome, safari).Then how will i do the same in chrome?
purnang.advant
A: 

i have the problem asp.net button click in google chrome . when i click the button first time it's works fine and second time it will work only double click and third time it will work on sixth click ... if any one help

asp:button id="BtnPrint" Text="Print" runat="server" onclick="fnPrint();"

function fnPrint() {

document.getElementById('<%=BtnPrint.ClientID %>').style.display = 'none';

window.print();

document.getElementById('<%=BtnPrint.ClientID %>').style.display = '';

return false; }

rajpandian