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?
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

erikTsomikSystem Architect, CF programmer Commented:
On Form subit through javascript you return false which stop the action.
Bane83Author Commented:
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.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Bane83Author Commented:
This is what I've tried:

<script type="text/javascript">
      var oldSubmit = document.forms[0].submit;
      document.forms[0].submit = function () { alert('Success!'); };

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?
Bane83Author Commented:
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.
You can add an onsubmit="return x" to the form tag to intercept any submit attempts
Bane83Author Commented:
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.
Bane83Author Commented:
Placing the event on Form submit wouldn't have worked properly in my situation.
I've managed to find an alternate solution and I will now be closing this question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.