Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
How can i show the progress with the progress bar while uploading the file with fileupload control?
i wrote the code like this file is uploading but progress bar is not showing the progress..

Code in the aspx file:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="updprogress.aspx.cs" Inherits="updprogress" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
    <script src="scripts/JScript.js" type="text/javascript"></script>

    <style type="text/css">
        .style1
        {
            width: 254px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
       <%-- <Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click"/>
</Triggers>--%>
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
                <asp:FileUpload ID="FileUpload1" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" >
        <ProgressTemplate>
        <img src="images/progressbar.jpg" height="40px" width="50"  />

        </ProgressTemplate>
        </asp:UpdateProgress>

    </div>
    </form>
</body>
</html>




Code in cs file:


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class updprogress : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void UpdateButton_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        System.Threading.Thread.Sleep(3000);
        FileUpload1.SaveAs(Server.MapPath("~/" + FileUpload1.FileName));
        Button1.Text = "uploaded successfully";
    }
}



Code in the script file:


var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args) {
    if (prm.get_isInAsyncPostBack())
        args.set_cancel(true);
    postBackElement = args.get_postBackElement();

    if (postBackElement.id == 'Button1')
        $get('UpdateProgress1').style.display = 'red';
}
function EndRequest(sender, args) {
    if (postBackElement.id == 'Button1')
        $get('UpdateProgress1').style.display = 'none';
}
Posted

Try giving below two attributes to your update panel.
ChildrenAsTriggers="true" UpdateMode="Conditional"
 
Share this answer
 
If you not want any too much code, than use simply Ajax file upload...
It will handle much more.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900