ASP.NET's server control postback uses this piece of JS code:
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit( );
}
}
The problem I encountered today is that I want to assign a value to one of the hidden fields before the server-side control posts back to pass the value to the server.
So I added an event using JQuery’s submit([[data],fn]) method, but found that it didn’t work.
I tried $("form:first").submit() and found that the event function can be triggered.
What’s going on? After checking the information, I found that the native function void submit() of js does not trigger the submit event. This is why there are
if (< ;span style="color:#006600">!theForm.onsubmit || (theForm.onsubmit() != false)) {
...
}
That’s it.
So write the add event as
$ ("form:first").get(0).onsubmit = function () {
...
};
That’s it.
In addition, events added using JQuery's submit([[data],fn]) can be triggered using $().submit().