First look at the code snippet below, we want the user to click on the button on the page to first submit the data to the specified third party page, and then perform the background of the Page_Load event.
Copy Code code as follows:
<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.target;
var oldmethod = O.method;
var iframesubmisiontarget = document.getElementById ("Webgatewaysubmissionprocessor_iframe");
var submitpostiframesubmission = function () {
O.action = oldaction;
O.target = 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.target = "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 the form is triggered when the page is submitted, and the Webgatewaydoublesubmission scripting method is executed first, in which the action,onsubmit,target of the current form, method is cached in the specified variable, and then the action and target of the form point to another page for submission, when the data on the page is posted to a Third-party page. Then use the hidden iframe on the page to invoke the Submitpostiframesubmission method and submit the original form. Here is a problem, a line in the above code is commented out, because the OnLoad method directly using the IFRAME does not trigger the event, causing the Submitpostiframesubmission method can not be executed, the second submission of the page is unsuccessful! Using the Eventpush method can be an effective solution to the problem.
At the same time, in the service-side Page_Load event, you need to use IsPostBack to determine whether the page has been submitted:
Copy Code code as follows:
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