Asp. NET instance: no refreshed file uploads

Source: Internet
Author: User
Tags bind file size file upload net blank page

Program Description

"Upload"

The most important method in the program is upload, which can be invoked without refreshing upload. The upload process is this, first stop the last upload with the Stop method, and decide whether to select files. Then call _setiframe,_setform and _setinput separately to generate the required iframe,form and input. If you set the Timeout property, the timer is set automatically:

The following are the referenced contents:
if (This.timeout > 0) {
This._timer = settimeout ($ $F. Bind (This._timeout, this), this.timeout * 1000);
}

PS: After testing, less than 0 of the delay time, IE will cancel execution, and other browsers will be executed as 0.

The program has a _sending attribute used to determine the upload status. At Stop (stop), remove (remove), _finis (finish), _timeout (timeout) will set it to false. and set it to true before the upload starts. The final submission of the form began to be uploaded.

"IFRAME"

The program uses the _setiframe function to create an IFRAME that does not need to be refreshed. Because the name of the IFRAME in IE cannot be modified, create an IFRAME like this:

The following are the referenced contents:
var iframename = "Quickupload_" + quickupload._counter++,
iframe = document.createelement ($ $B. ie? "<iframe name=\" "+ iframename +" \ ">": "iframe");
Iframe.name = Iframename;
Iframe.style.display = "None";

PS: Questions about the name of the IFRAME refer to the IFRAME section here . IE8 has been able to modify name, but it cannot be modified in a non-standard (odd) mode. It uses a quickupload function's own _counter property as a calculator, which guarantees that the name of the IFRAME for each instance will not be duplicated.

In order to execute the callback function after the file upload is completed, the _finish function is executed in the onload of the IFRAME:

The following are the referenced contents:
var finish = This._ffinish = $ $F. Bind (This._finish, this);
if ($ $B. IE) {
Iframe.attachevent ("onload", finish);
} else {
Iframe.onload = $ $B. Opera? function () {this.onload = finish;}: Finish;
}

In IE need to use attachevent to bind onload, because in IE directly set onload is invalid. In addition to using attachevent can also be replaced with onreadystatechange. As for the reasons I am not clear, detailed reference to " determine whether the IFRAME loading complete the perfect method ."

There is also a problem with the loading of IFRAME, test the following code:

The following are the referenced contents:
<body><div id= "msg" > Status:</div></body>
<script>
var msg = document.getElementById ("msg");
var iframe = document.createelement ("iframe");
Iframe.onload = function () {msg.innerhtml + = "onload,";}
Document.body.appendChild (IFRAME);
IFRAME.SRC = "http://cloudgamer.cnblogs.com/"
</script>

As a result safari, Chrome will trigger the onload two times, while opera, FF and IE (please be compatible) are 1 times.

It is estimated that safari and chrome are loaded for the first time after appendchild, and the load is completed before SRC is set, so two times is triggered. If an IFRAME is randomly set to the body before inserting the body (except for the null value), the indirect length is first loaded, and then it is triggered only once. PS: src without setting or null value is equivalent to linking to "About:blank" (Blank page).

Then opera, FF and IE may be the first time to load too slow, the second cover the first time, so only triggered a onload. PS: There may also be other reasons, such as browser optimization and so on, I am not sure.

For the problem of too fast loading, can be in the onload time according to _sending to determine whether the upload status to solve. Although not tested out, will there be _sending settings after submit just before the first onload situation?
To address this problem, the upload method will place the _sending after the submit setting. What if the onload is triggered before _sending is set up after the submit? (... This situation basically will not appear, if really appear, put the _sending settings to submit to the front bar.

Opera also has a problem to test the following code:

The following are the referenced contents:
<body>
<div id= "msg" > Status:</div>
<form action= "http://cloudgamer.cnblogs.com/" target= "IFR" >
</form>
</body>
<script>
var msg = document.getElementById ("msg");
var iframe = document.createelement ("iframe");
Iframe.name = "IFR";
Iframe.onload = function () {msg.innerhtml + = "onload,";}
Document.body.appendChild (IFRAME);
Msg.innerhtml + + "Submit,";
Document.forms[0].submit ();
</script>

IE and FF display Submit,onload,safari and Chrome show the onload,submit,onload, consistent with the above analysis. But opera shows Submit,onload,onload, two times the onload is triggered after the submit. This situation can not be solved simply with _sending. Is the submit not allowed to cancel the iframe load? Before AppendChild set a src, the result is normal only trigger the onload once, it seems to be possible ah.

Although do not know the reason, the solution is still some, one is appendchild before setting up a SRC, can also in the first onload to reset the onload, like the program. But these two methods are uncertain, can not completely solve the problem, but also can not find a better way.

FF's onload There is also a problem, in the presence of Error_internet_connection_reset (file size exceeds the server limit), such as server errors, even if the load completion will not trigger the onload, temporarily find no solution.

An IFRAME has a flaw that can only be used to judge the loading complete, but there is no way to determine whether the load succeeds. There is no such thing as the status of the XMLHTTP, there is no way to judge the mistakes of 404. In the use of this to do a good job, such as the description of the allowable upload file size, timeout time, how to deal with a long time no response.



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.