Asyncfileupload: File Upload in updatepanel, ASP. NET Ajax

Source: Internet
Author: User

Ajax Control Toolkit release

September 2009 Release
Version 3.0.30930

 

 

 

 

 

Default. aspx

 

<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "default. aspx. CS "inherits =" asyncfileupload. _ default "%> </P> <p> <% @ register Assembly =" ajaxcontroltoolkit "namespace =" ajaxcontroltoolkit "tagprefix =" PC3 "%> </P> <p> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </P> <p> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead id = "head1" runat = "server"> <br/> <title> asyncfileupload, ASP. net, Ajax </title> </P> <p> <SCRIPT type = "text/JavaScript"> <br/> var begin; <br/> function asyncfileupload1_uploaderror (sender, ARGs) <br/>{< br/> document. geteleme Ntbyid ('lblupload '). innertext = "sorry, file" "+ args. get_filename () + "" Upload error. Cause: "+ args. get_errormessage (); <br/>}</P> <p> function asyncfileupload1_startupload (sender, argS) <br/>{< br/> begin = new date (); <br/> document. getelementbyid ('lblupload '). innertext = "file" + args. get_filename () + "" Uploading... please wait "; <br/>}</P> <p> function asyncfileupload1_uploadcomplete (sender, argS) <br/> {<br/> var t = (new date ()). Valueof ()-begin. valueof (); <br/> var speed = math. round (ARGs. get_length ()/1.024/T); <br/> document. getelementbyid ('lblupload '). innertext = "Upload" + args. get_length () + "byte, time spent" + T + "millisecond, speed:" + speed + "kb/s "; <br/>}< br/> </SCRIPT> <br/> </pead> <br/> <body style = "font-size: 14px; font-family: "> <br/> <Form ID =" form1 "runat =" server "> <br/> <div> <br/> <Div id =" content "> <br/> <asp: scriptmanage R id = "scriptmanager1" runat = "server"> <br/> </ASP: scriptmanager> <br/> <Table width = "100%" border = "1" cellspacing = "0" cellpadding = "5"> <br/> <tr> <br/> <TD> upload a file: </TD> <br/> <asp: updatepanel id = "updatepanel1" runat = "server"> <br/> <contenttemplate> <br/> <PC3: asyncfileupload id = "asyncfileupload1" runat = "server" <br/> onclientuploadcomplete = "asyncfileupload#uploadcomplete" <br/> onclientuploaderro R = "asyncfileupload1_uploaderror" <br/> onclientuploadstarted = "asyncfileupload#startupload" <br/> onuploadedcomplete = "login"/> <br/> <asp: label id = "lblupload" runat = "server"> </ASP: label> <br/> </contenttemplate> </P> <p> <triggers> <br/> <asp: asyncpostbacktrigger controlid = "asyncfileupload1" eventname = "uploadedcomplete"/> <br/> </triggers> <br/> </ASP: updatepanel> <br/> </TD> <br /> </Tr> </P> <p> <tr> <br/> <TD> & nbsp; </TD> <br/> <asp: Label id = "label1" runat = "server" text = "1"> </ASP: label> <br/> <asp: Label id = "label2" runat = "server" text = "Left value is used to test whether the entire page is refreshed! "Forecolor =" red "> </ASP: label> <br/> </TD> <br/> </tr> <br/> </table> <br/> </div> <br/> </ div> <br/> </form> <br/> </body> <br/> </ptml>

 

 

Default. aspx. CS

Using system; <br/> using system. collections; <br/> using system. configuration; <br/> using system. data; <br/> using system. data. oledb; <br/> using system. LINQ; <br/> using system. web; <br/> using system. web. security; <br/> using system. web. ui; <br/> using system. web. UI. htmlcontrols; <br/> using system. web. UI. webcontrols; <br/> using system. web. UI. webcontrols. webparts; <br/> using system. XML. LINQ; </P> <p> namespace asyncfileupload <br/> {<br/> Public partial class _ default: system. web. UI. page <br/>{< br/> protected void page_load (Object sender, eventargs e) <br/>{< br/> If (ispostback) <br/>{< br/> label1.text = (Int. parse (label1.text) + 1 ). tostring (); <br/>}</P> <p> protected void asyncfileupload#uploadedcomplete (Object sender, ajaxcontroltoolkit. asyncfileuploadeventargs e) <br/>{< br/> If (asyncfileupload1.hasfile) <br/>{< br/> asyncfileupload1.postedfile. saveas (server. mappath (". /") + asyncfileupload1.filename); <br/>}< br/>}

 

 

To upload a large file, you must modify the value of Web. config,

Add content in system. Web

 

<System. Web>
<! -- Maxrequestlength controls the maximum file size that can be uploaded. Unit: KB -->
<Httpruntime maxrequestlength = "2097151"/>
...
</System. Web>

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.