Reputation: 3243
I am trying to make my application compatible with all browsers and my code
ClientScript.RegisterClientScriptBlock(this.GetType(), "theAction",
"<script type='text/javascript'>
function DoSave() {
try {
document.all('" + lbnSave.ClientID + "').click();
} catch(e){}
}
</script>");
is working in IE8, Chrome and Opera, but not in Firefox. I know that document.all is IE specific, but how do I rewrite this to work in Firefox too? Many Thanks!
Upvotes: 0
Views: 2078
Reputation: 12815
Use getElementById
which is cross-browser:
ClientScript.RegisterClientScriptBlock(this.GetType(), "theAction",
"function DoSave() {
try {
document.getElementById('" + lbnSave.ClientID + "').click();
} catch(e){}
}", true);
Also, you can make your code cleaner. Fourth parameter set to true
will add <script>
tag automatically.
Upvotes: 1