Problems with using IFRAME to submit form data on ASP. NET pages

Source: Internet
Author: User

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

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.