Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have written code like,

JavaScript
document.getElementById("<%= btnVillageSearch.ClientID %>").click();


To Perform Click Operation which working in Mozilla Firefox, But while coming to IE,

It is not supporting. Please tell me how to perform button click from Java Script for

IE.
Posted
Updated 11-Oct-12 23:02pm
v2
Comments
I.explore.code 12-Oct-12 2:56am    
Are u missing a "#" after "<%"? The other thing u could try is set the clientidmode property to static of the button and then access the id directly in your JavaScript as a literal string. See if that works.

1 solution

XML
var btn = document.getElementById('<%=btnDummy.ClientID%>');
btn.click();

This is something i have used previously and can confirm it works in IE. , also try moving the the script block to the end of the page, it might also have something to the version of IE you are using.

Or you can try this, this is something i used in Safari which wouldnt otherwise fire the click() event properly
C#
var dispatch = document.createEvent("HTMLEvents")
dispatch.initEvent("click", true, true);
document.getElementById('<%=btnDummy.ClientID%>').dispatchEvent(dispatch);


Hope it helps.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900