[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1992
  • Last Modified:

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?
0
Bane83
Asked:
Bane83
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
0
 
Maverick_CoolCommented:
On Form subit through javascript you return false which stop the action.
0
 
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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!'); };
 </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.
0
 
NazoUKCommented:
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?
0
 
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.
0
 
NazoUKCommented:
You can add an onsubmit="return x" to the form tag to intercept any submit attempts
0
 
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.
0
 
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.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now