Bane83
asked on
Any way to override the submit function?
I've created a function which overrides the __doPostBack function and will only allow it to run under certain conditions. This is great, but if you put an asp:Button onto the page and click it, the __doPostBack function is not used.
I'm not exactly sure what else I may need to override here. Anyone have any ideas?
I'm not exactly sure what else I may need to override here. Anyone have any ideas?
On Form subit through javascript you return false which stop the action.
ASKER
erikTsomik, that is Opera specific.
Maverick_Cool, I do not need to know how to cancel a submit, I already know that.
What I want to know is the name of the function which is run when a page is being submitted.
__doPostBack is one of these functions but is used only for controls with AutoPostBack="true", I've already overriden this. There is another function which is being run and I need to know what is called and whether or not I can override it, not cancel, but give it a new definition.
Maverick_Cool, I do not need to know how to cancel a submit, I already know that.
What I want to know is the name of the function which is run when a page is being submitted.
__doPostBack is one of these functions but is used only for controls with AutoPostBack="true", I've already overriden this. There is another function which is being run and I need to know what is called and whether or not I can override it, not cancel, but give it a new definition.
ASKER
This is what I've tried:
<script type="text/javascript">
var oldSubmit = document.forms[0].submit;
document.forms[0].submit = function () { alert('Success!'); };
</script>
And this works, I can override the submit function, however I'm not sure why (possibly because I'm using an AJAX enabled site), it's still using the old submit function.
<script type="text/javascript">
var oldSubmit = document.forms[0].submit;
document.forms[0].submit = function () { alert('Success!'); };
</script>
And this works, I can override the submit function, however I'm not sure why (possibly because I'm using an AJAX enabled site), it's still using the old submit function.
Under normal circustances no script is executed when you press a button, it's just a regular form submit. You could add an onclientclick handler to do custom post logic if you like. What happens in an Ajax enabled site, I'm not sure. Can't you view the source and see what is in the button tag?
ASKER
Unfortunately, no. With an AJAX site, nothing gets bound to any of the client controls. It's all external and it binds to the existing framework, I believe. I was wrong about it not overriding due to it being an AJAX site though. I've created a non-AJAX site and with the same script, it still doesn't work.
Trouble is that I don't want any code on any particular control that's on the page. I'm trying to create a control which will intercept the attempt at the submit, do it's thing, then let the page do it's thing. That's why I need to specifically override the page's submit function. Easy enough with the __doPostBack, but this next piece is giving me a run for my money.
Trouble is that I don't want any code on any particular control that's on the page. I'm trying to create a control which will intercept the attempt at the submit, do it's thing, then let the page do it's thing. That's why I need to specifically override the page's submit function. Easy enough with the __doPostBack, but this next piece is giving me a run for my money.
You can add an onsubmit="return x" to the form tag to intercept any submit attempts
ASKER
I actually did attempt that. What I did was in my control's behavior prototype, I've added script which grabs the current onsubmit event (if any) so that I don't overwrite it and leave the end user wondering what's going on and saves it. Then, it overwrites the form.onsubmit with my new __doPostBack event. Seemed like a good idea... except that my new __doPostBack will call the old __doPostBack at some point and the old __doPostBack calls form.onsubmit... which calls my new __doPostBack which calls the old __doPostBack, which calls form.onsubmit... you get the picture. :P
I was thinking about that, and I think that at some logical point I will have to switch the form.onsubmit back to the old form.onsubmit, but I'm not too keen on this whole method as it is. It seems somewhat kludgey to me, and I would like, if at all possible, to find a better solution before commiting to it.
I was thinking about that, and I think that at some logical point I will have to switch the form.onsubmit back to the old form.onsubmit, but I'm not too keen on this whole method as it is. It seems somewhat kludgey to me, and I would like, if at all possible, to find a better solution before commiting to it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.opera.com/support/tutorials/userjs/examples/