ASP.NET2.0:Ilungasoft.Framework.Web之基於Callback的無重新整理上傳進度條控制項[帶源碼]

來源:互聯網
上載者:User
asp.net|web|控制項|上傳|重新整理|無重新整理

共用一個基於Callback的無重新整理上傳進度條控制項的源碼。本控制項使用的HttpMoudule基於寶玉的一個上傳進度條的sample,這裡封裝為一個控制項,方便使用。無需任何代碼,只需設定web.config,添加HttpModule的引用,再將控制項拖到頁面就行。頁面中的檔案儲存操作和傳統的asp.net檔案上傳完全一樣。可以設定屬性上傳過程中出錯或上傳成功時跳轉到其它頁面。相容IE,Firefox,Opera。其它環境沒測試,不過因為是基於Asp.Net2.0的callback,其他瀏覽器只要支援xmlhttp或iframe就應該支援。

線上示範請訪問:http://teddy.cn/test

源碼及樣本下載http://teddyma.cnblogs.com/Files/teddyma/TestUploadProgressBar.zip

(在本機運行樣本注意將程式所在目錄設為對web帳號可寫,否則上傳檔案是會許可權不足報錯)

下面簡單列舉一下樣本中的web.config和Default.aspx和Default.aspx.cs。

web.config

 1<?xml version="1.0"?>
 2<configuration>
 3    <appSettings/>
 4    <connectionStrings/>
 5    <system.web>
 6        <compilation debug="true"/>
 7        <authentication mode="Windows"/>
 8    <httpModules>
 9      <add name="HttpUploadModule" type="Ilungasoft.Framework.Web.Modules.UploadProgressModule, Framework.Web"/>
10    </httpModules>
11    <httpRuntime maxRequestLength="1000000" executionTimeout="300"/>
12  </system.web>
13</configuration>
Default.aspx (注意Line 17必須設定控制項的UploadButtonName為頁面中出發上傳事件的按鈕的ID)

 1<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 2
 3<%@ Register Assembly="Framework.Web" Namespace="Ilungasoft.Framework.Web.UI.WebControls"
 4    TagPrefix="cc1" %>
 5<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 6<html xmlns="http://www.w3.org/1999/xhtml">
 7<head id="Head1" runat="server">
 8    <title>Untitled Page</title>
 9</head>
10<body>
11    <form id="form1" runat="server">
12        <div>
13            <asp:FileUpload ID="FileUpload1" runat="server" /><br />
14            <br />
15            <asp:Button ID="Button1" runat="server" Text="Upload" /><br />
16            <br />
17            <cc1:UploadProgressBar ID="UploadProgressBar1" runat="server" UploadButtonName="Button1" UploadErrorRedirectUrl="UploadError.aspx">
18            </cc1:UploadProgressBar>
19              <br />
20            <br />
21        </div>
22    </form>
23</body>
24</html>
Default.aspx.cs

 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10
11public partial class _Default : System.Web.UI.Page
12{
13    protected void Page_Load(object sender, EventArgs e)
14    {
15
16    }
17    protected void Button1_Click(object sender, EventArgs e)
18    {
19        FileUpload1.SaveAs(Server.MapPath("test.tmp"));
20    }
21}
是不是沒感覺到和使用該控制項之前相比多了任何代碼呢?;-)

Enjoy!



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.