Atlas uploads attachments in updatepanel

Source: Internet
Author: User
Speaking of the last time (discussing with Atlas experts some bugs and questions about Atlas), it is difficult to use fileupload to upload attachments in Atlas: updatepanel only sends an XMLHTTP request and viewstate each time, the entire page is not resent. Therefore, fileupload files cannot be obtained on the server.

The first solution is not to use updatepanel: a new window pops up to upload files. Updatepanel is not used in the new window. Of course this method works.

Today, I suddenly remembered that uploading attachments in Gmail: uploading files in the background does not affect the editing of your front-end emails or refresh the overall page. This mode is handsome! You do not need to open a new window, but do not need to refresh a page.

After comparison, it seems that the second method is better. So firebug (Ajax Program Tracking Tool: firebug0.4) Gmail, found that the processing inside is like this < IFRAME Scrolling = "Auto" Frameborder = "0" Onload = "Try {If (top. js. init) top. js. _ if_onloaded ('v1 ') < Input Type = "File" Onchange = "Top. js. _ cm_onattach (window, this )" Name = "F_ephki04a" Size = "50" />

The uploaded attachment is placed inIn the IFRAME, and some processing is performed in the onchange event of the control.

It is a good method.
So I made such a solution:
1: Use updatepanel on the home page. Then, the updatepanel contains an IFRAME instead of the fileupload control.
2: This IFRAME is linked to a new page, which contains the fileupload control.
3: After the upload is complete, tell the home page the upload result.

First, let's look at an example of using fileupload directly: In this example, the server cannot find the file to be uploaded. < Atlas: updatepanel ID = "Up1" Mode = "Conditional" Runat = "Server" >
< Contenttemplate >
< ASP: fileupload ID = "Fileupload1" Runat = "Server"   />
< ASP: button ID = "Button1" Runat = "Server" Text = "Button" Onclick = "Button#click"   />
</ Contenttemplate >
</ Atlas: updatepanel >


Let's see how we can implement it.
1: create default. aspx on the home page
Place an updatepanel area of the uploaded attachment in the appropriate location.

< Atlas: updatepanel ID = "Up_attachment" Mode = "Conditional" Runat = "Server" >
< Contenttemplate >
< IFRAME ID = "File" Name = "File" SRC = "Attachment. aspx" > </ IFRAME >
</ Contenttemplate >
</ Atlas: updatepanel >

2: Create the attachment. ASPX page for the file to be uploaded, and then place the fileupload control. < Div >
< ASP: fileupload ID = "Fileupload1" Runat = "Server"   />
< ASP: button ID = "Button1" Runat = "Server" Text = "OK" Onclick = "Button#click"   />
</ Div >

3: In attachment. aspx, upload the file and call the JS on the home page to report the upload status. This is a function prototype:<Script>
Window. Top. Callback (filename );
</Script>

4: add this function on the default. aspx homepage to process the returned values.

< Script >
Function callback (filename)
{
Document. getelementbyid ('Attach1'). Innerhtml=Filename;
}
</ Script >

Then, complete the process.
This solution, although there are still two pages, but it seems that the processing is in one page, the page processing is refreshing.

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.