Asp. NET page The solution to the problem of submitting form data with IFrame sharing _ practical Tips

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.