First, let's take a look at the followingCodeSegment, we want the user to first submit the data to the specified third-party page when clicking the button on the page, and then execute the page_load event in the background.
< Body >
< IFRAME ID = "Webgatewaysubmissionprocessor_iframe" Name = "Webgatewaysubmissionprocessor_iframe" Style = "Display: none ;" > </ IFRAME >
< Form Onsubmit = "Javascript: If (typeof webgatewaydoublesubmission! = 'Undefined') {webgatewaydoublesubmission (this );}" ID = "Form1" Runat = "Server" >
< Div ID = "Page" >
< ASP: button ID = "Btnclientsend" Runat = "Server" />
</ Div >
< Script Type = "Text/JavaScript" ID = "Webgatewayscript" >
Webgatewaydoublesubmission = Function (O ){
VaR Oldaction = O. Action;
VaR Oldonsubmit = O. onsubmit;
VaR Oldtarget = O.tar get;
VaR Oldmethod = O. method;
VaR Iframesubmisiontarget = Document. getelementbyid ( " Webgatewaysubmissionprocessor_iframe " );
VaR Submitpostiframesubmission = Function (){
O. Action = Oldaction;
O.tar get = Oldtarget;
O. Method = Oldmethod;
O. onsubmit = Oldonsubmit;
O. Submit ();
};
/* Iframesubmisiontarget. onload = submitpostiframesubmission; */
Eventpush (iframesubmisiontarget, ' Load ' , Submitpostiframesubmission );
O. Action = " Http://webgateway.hostedmscrm.com/V2/formprocessor.aspx " ;
O.tar get = " Webgatewaysubmissionprocessor_iframe " ;
O. onsubmit = Null ;
O. Method = " Post " ;
O. Submit ();
};
Webgatewaysubmission = Function (O ){
O. Action = " Http://webgateway.hostedmscrm.com/V2/formprocessor.aspx " ;
O. Method = " Post " ;
};
Function Eventpush (OBJ, event, Handler ){
If (Obj. addeventlistener ){
OBJ. addeventlistener (event, handler, False );
} Else If (Obj. attachevent ){
OBJ. attachevent ( ' On ' + Event, Handler );
}
}
</ Script >
</ Form >
</Body>
The onsubmit event in form is triggered when the page is submitted. At this time, the webgatewaydoublesubmission script method is first executed. In this method, the current form action, onsubmit, target, the method is cached in the specified variable, and then the form action and target point to another page for submission. At this time, the data on the page is post to a third-party page. Then, use the hidden IFRAME on the page to call the submitpostiframesubmission method and submit the original form. Here is a problem. One line in the above Code has been commented out because the onload method of IFRAME cannot be used to trigger this event. As a result, the submitpostiframesubmission method cannot be executed, the second page submission failed! The eventpush method can effectively solve this problem.
At the same time, in the page_load event of the server, ispostback is required to determine whether the page has been submitted:
Protected Void Page_load ( Object Sender, eventargs E)
{
If (Page. ispostback)
{
// Todo:
}
}
Related information:
Http://www.4ucode.com/Study/Topic/1087401
http://wiki.operamasks.org/pages/viewpage.action? Pageid = 1835020