I am trying this command "document.getElementById('myButton').click();"
to execute from client-side a button's server-side event. It works fine in IE7, but Firefox (2.0 & 3.0) just doesnt recognize it, raising me a javascript error (tells me its not a function)...I tried with "document.getElementById('myButton').onclick();" with
no avail...
I am really stuck with this issue, Ive been struggling for weeks with stuff!!!!
Any help will be HIGHLY appreciated!
We are here to learn, and teach whenever possible...
rtortima
Member
314 Points
419 Posts
document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 22, 2008 09:01 PM|LINK
I am trying this command "document.getElementById('myButton').click();" to execute from client-side a button's server-side event. It works fine in IE7, but Firefox (2.0 & 3.0) just doesnt recognize it, raising me a javascript error (tells me its not a function)...I tried with "document.getElementById('myButton').onclick();" with no avail...
I am really stuck with this issue, Ive been struggling for weeks with stuff!!!!
Any help will be HIGHLY appreciated!
A1ien51
All-Star
29935 Points
5821 Posts
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 22, 2008 09:39 PM|LINK
Just call the function that the click event calls. If it is a normal postback, than call the __doPostBack.
Eric
shashankgwl
All-Star
18926 Points
3662 Posts
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 23, 2008 03:29 AM|LINK
try instead onclick='document.forms[0].submit'
All is well if it runs well.
blog
rtortima
Member
314 Points
419 Posts
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 23, 2008 11:03 AM|LINK
Could you elaborate a little bit more on this, maybe with an example?
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 23, 2008 01:02 PM|LINK
What does the click event of the button do? If all it does is submit the page, try this:
<script type="text/javascript">
<!--
function someFunction()
{
// Your code...
//document.getElementById('myButton').click();
<%= GetPostBackEventReference(myButton, string.Empty) %>;
}
// -->
</script>
If using VS 2.0 use this GetPostBackEventReference call instead: ClientScript.GetPostBackEventReference(myButton, string.Empty)
NC..
rtortima
Member
314 Points
419 Posts
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 23, 2008 02:27 PM|LINK
I tried the suggestions...with no avail.
Also, I tried the code below, in IE7 it works fine, in Firefox I get no error, but nothing happens either :(
if (button.dispatchEvent)
{
var e = document.createEvent(“MouseEvents”);
e.initEvent(“click”, true, true);
button.dispatchEvent(e);
}
else
{
button.click();
}
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: document.getElementById('myButton').click(); ...just doesnt work in Firefox, WHY IS THAT?
Nov 27, 2008 12:51 PM|LINK
That is NOT going to work in all browsers. Did you try the code that I posted? I know that works as I just tried it in IE and Firefox.
NC...