An example of the difference between JQuery and JS submit of


ASP.NET server control postback is using this section 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 today is that you want to assign a value to one of the hidden fields to pass a value to the server before the server-side control posts back.

So I added an event using JQuery’s submit([[data],fn]) method, but it didn’t work.

I tried it out with $(“form:first”). Submit () and found that it triggers the event function.

What’s going on? Checking the data, we found that js’s native function void submit() does not trigger a submit event. That’s why it’s in the code above, right


if (<span style="color:#006600">!theForm.onsubmit || (theForm.onsubmit() != false</span>)) {
...
}

This sentence.

So let’s write the add event


$("form:first")<span style="color:#006600">.get(0)</span>.onsubmit = function () {
...
};

That’s it.

In addition, the events added with JQuery’s submit([[data],fn]) can be triggered with $().submit().