In a page i have multiple file upload under update panel also i have an update progress in that page. When I am uploading files the update progress is not showing. please follow the aspx and aspx.cs code and help me.
.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/AdminMaster.master" AutoEventWireup="true" CodeFile="CreateEditDocument.aspx.cs" Inherits="CreateNewDocument" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 80%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" Runat="Server">
<h3>Create New Document</h3>
<p>
<asp:Label ID="LabelCurrentUser" runat="server" Text="">Current User : </asp:Label>
<asp:Label ID="lblCurrentUser" runat="server" Text=""></asp:Label>
</p>
<p>
<asp:Label ID="LabelCurrentUserRole" runat="server" Text="">Current User Role : </asp:Label>
<asp:Label ID="lblCurrentUserRole" runat="server" Text=""></asp:Label>
</p>
<p></p>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="auto-style1">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocNumber" runat="server" Text="">Document Number :</asp:Label>
</td>
<td>
<asp:TextBox ID="txtDocNumber" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtDocNumber" ErrorMessage="*">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocSubject" runat="server" Text="">Document Subject :</asp:Label>
</td>
<td>
<asp:TextBox ID="txtDocSubject" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID ="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="txtDocSubject">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocName" runat="server" Text="">Document Name :</asp:Label>
</td>
<td>
<asp:TextBox ID="txtDocName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID ="RequiredFieldValidator3" runat="server" ErrorMessage="*" ControlToValidate="txtDocName">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocUploadFile" runat="server" Text="">Upload Document :</asp:Label>
</td>
<td>
<asp:Panel ID="panelFileUpload" runat="server">
<asp:FileUpload ID="fuploadDoc" runat="server" Class="multi" accept=".jpg|.jpeg|.doc|.docx|.pdf|.png|.gif|.xls|.xlsx" /> <br />
</asp:Panel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelUploadedFileList" runat="server" Text="Uploaded File List"></asp:Label>
</td>
<td>
<asp:Panel ID="panelUploadedFileList" runat="server">
<asp:GridView ID="gvDocFileList" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDeleted="gvDocFileList_RowDeleted" OnRowDeleting="gvDocFileList_RowDeleting">
<Columns>
<asp:BoundField HeaderText="File ID" DataField="DocFileID" ReadOnly="true" />
<asp:BoundField HeaderText="Document ID" DataField="DocID" ReadOnly="true" />
<asp:TemplateField HeaderText="File Name">
<ItemTemplate>
<asp:HyperLink ID="hlinkDocFilePath" runat="server" Text='<%# Bind("DocFilePath") %>' NavigateUrl='<%#Eval("DocFilePath") %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
</asp:Panel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelComments" runat="server" Text="">Comments :</asp:Label>
</td>
<td>
<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" Width="300px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelCreatedBy" runat="server" Text="">Created By :</asp:Label>
</td>
<td>
<asp:Label ID="lblCreatedBy" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelCreatedDT" runat="server" Text="">Created Date Time :</asp:Label>
</td>
<td>
<asp:Label ID="lblCreatedDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocumentPriority" runat="server" Text="">Priority :</asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDocPriority" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocType" runat="server" Text="">Document Type :</asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDocType" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="LabelDocStatus" runat="server" Text="">Document Status :</asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDocStatus" runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnCreateDocument" runat="server" Text="Create Document" CssClass="btn btn-primary" OnClick="btnCreateDocument_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" CssClass="btn btn-danger" OnClick="btnCancel_Click" />
</td>
</tr>
<tr>
<td> </td>
<td>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="lblStatus" runat="server" Font-Bold="True" Font-Size="Medium"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnCreateDocument"/>
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="0">
<ProgressTemplate>
<div id="LoadingDiv">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Loading_Images/waitAnimated.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
.aspx.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
public partial class CreateNewDocument : System.Web.UI.Page
{
DMS_Functionalities objDMS = new DMS_Functionalities();
UI_Operation objUI = new UI_Operation();
LogDetails objLogDetails = new LogDetails();
Hashtable paramList = new Hashtable();
Hashtable fileParamList = new Hashtable();
DataSet ds = new DataSet();
int dsLength, saveFileFlag = 0;
string docFilePath = string.Empty;
string serverFilePath = string.Empty;
string docNumber = string.Empty;
ArrayList arrFileNames = new ArrayList();
bool status, docFileStatus;
//static int fuCounter = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["userID"] != null && Session["userRole"] != null)
{
lblCurrentUser.Text = Convert.ToString(Session["userID"]);
lblCurrentUserRole.Text = Convert.ToString(Session["userRole"]);
invisibleCreatedDetails();
}
else
{
Session.Clear();
Response.Redirect("Login.aspx");
}
fillDocTypes(ddlDocType);
fillStatus(ddlDocStatus);
fillDocPriority(ddlDocPriority);
if (Request.QueryString["DocNumber"] != null && btnCreateDocument.Text == "Create Document")
{
docNumber = Convert.ToString(Request.QueryString["DocNumber"]);
fillDocDetails(docNumber);
visibleCreatedDetails();
fillDocFileList(docNumber);
btnCreateDocument.Text = "Update Document";
txtDocNumber.Enabled = false;
}
else
{
docNumber = "NA";
LabelUploadedFileList.Visible = false;
panelUploadedFileList.Visible = false;
}
}
}
protected void fillDocDetails(string doc_Number)
{
ds = new DataSet();
ds = objDMS.getSpecificDocDetails(docNumber);
txtDocNumber.Text = docNumber;
txtDocSubject.Text = ds.Tables[0].Rows[0]["DocSubject"].ToString();
txtDocName.Text = ds.Tables[0].Rows[0]["DocName"].ToString();
txtComments.Text = ds.Tables[0].Rows[0]["DocComments"].ToString();
lblCreatedBy.Text = ds.Tables[0].Rows[0]["CreatedBy"].ToString();
lblCreatedDT.Text = ds.Tables[0].Rows[0]["CreatedDateTime"].ToString();
ddlDocStatus.Text = ds.Tables[0].Rows[0]["DocStatus"].ToString();
ddlDocPriority.Text = ds.Tables[0].Rows[0]["DocPriority"].ToString();
ddlDocType.Text = objDMS.getDocTypeForSpecificDocNumber(txtDocNumber.Text.Trim());
}
protected void fillDocFileList(string doc_Number)
{
ds = new DataSet();
ds = objDMS.getAllFilesDetailsForSpecificDoc(doc_Number);
gvDocFileList.DataSource = ds;
gvDocFileList.DataBind();
}
protected void fillStatus(DropDownList ddlStatus)
{
ds = new DataSet();
ds = objDMS.getAllStatus();
if (ds.Tables[0].Rows.Count > 0)
{
ddlStatus.Items.Clear();
dsLength = ds.Tables[0].Rows.Count;
for (int i = 0; i < dsLength; i++)
ddlStatus.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
else
ddlStatus.Items.Clear();
}
protected void fillDocPriority(DropDownList ddlPriority)
{
ds = new DataSet();
ds = objDMS.getAllPriority();
if (ds.Tables[0].Rows.Count > 0)
{
ddlPriority.Items.Clear();
dsLength = ds.Tables[0].Rows.Count;
for (int i = 0; i < dsLength; i++)
ddlPriority.Items.Add(Convert.ToString(ds.Tables[0].Rows[i][1]));
}
else
ddlPriority.Items.Clear();
}
protected void fillDocTypes(DropDownList ddlTypes)
{
ds = new DataSet();
ds = objDMS.getAllDocumentTypes();
if (ds.Tables[0].Rows.Count > 0)
{
ddlTypes.Items.Clear();
dsLength = ds.Tables[0].Rows.Count;
for (int i = 0; i < dsLength; i++)
ddlTypes.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
else
ddlTypes.Items.Clear();
}
protected void visibleCreatedDetails()
{
LabelCreatedBy.Visible = true;
LabelCreatedDT.Visible = true;
lblCreatedBy.Visible = true;
lblCreatedDT.Visible = true;
}
protected void invisibleCreatedDetails()
{
LabelCreatedBy.Visible = false;
LabelCreatedDT.Visible = false;
lblCreatedBy.Visible = false;
lblCreatedDT.Visible = false;
}
protected void uploadFilesToServer(string operation_mode)
{
HttpFileCollection files = Request.Files;
string fileName = string.Empty;
string dirPath = string.Empty;
string fileExt = string.Empty;
string countName = string.Empty;
string docFileNamePath = string.Empty;
int _maxID;
arrFileNames = new ArrayList();
_maxID = objDMS.getMaxDocFileID();
if (operation_mode == "CREATE")
{
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (file.ContentLength > 0)
{
dirPath = Server.MapPath("~/Docs/");
fileExt = Path.GetExtension(file.FileName);
//countName = Convert.ToString(i + 1);
_maxID++;
fileName = _maxID + fileExt;
serverFilePath = dirPath + fileName;
docFileNamePath = "~/Docs/" + fileName;
arrFileNames.Add(docFileNamePath);
file.SaveAs(serverFilePath);
}
}
}
else
{
//int existFileNumber = objDMS.getNumberofFilesForSpecificDoc(txtDocNumber.Text.Trim());
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (file.ContentLength > 0)
{
dirPath = Server.MapPath("~/Docs/");
fileExt = Path.GetExtension(file.FileName);
//existFileNumber = existFileNumber + 1;
//countName = Convert.ToString(existFileNumber);
_maxID++;
fileName = _maxID + fileExt;
serverFilePath = dirPath + fileName;
docFileNamePath = "~/Docs/" + fileName;
arrFileNames.Add(docFileNamePath);
file.SaveAs(serverFilePath);
}
}
}
}
protected void saveUploadedFiles(string _mode)
{
uploadFilesToServer(_mode);
saveFileFlag = 0;
int doc_id;
// Code segment for saving all the files to the database for a particular document
if (_mode == "CREATE")
doc_id = objDMS.getMaxDocID();
else
{
ds = new DataSet();
ds = objDMS.getSpecificDocDetails(txtDocNumber.Text.Trim());
doc_id = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
}
for (int i = 0; i < arrFileNames.Count; i++)
{
fileParamList = new Hashtable();
fileParamList.Add("@opMode", "INSERT");
fileParamList.Add("@DocFileID", 0);
fileParamList.Add("@DocID", doc_id);
fileParamList.Add("@DocFilePath", arrFileNames[i].ToString());
fileParamList.Add("@ModifiedBy", lblCurrentUser.Text.Trim());
fileParamList.Add("@ModifiedDT", DateTime.Now);
docFileStatus = objDMS.CRUD_DocFileDetails(fileParamList);
if (!docFileStatus)
saveFileFlag = saveFileFlag + 1;
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("LoginHome.aspx");
}
protected void btnCreateDocument_Click(object sender, EventArgs e)
{
string operationMode = string.Empty;
System.Threading.Thread.Sleep(10000);
if (btnCreateDocument.Text == "Create Document")
{
btnCreateDocument.Text = "Please Wait...";
paramList = new Hashtable();
operationMode = "CREATE";
paramList.Add("@Mode", "INSERT");
paramList.Add("@DocNumber", txtDocNumber.Text.Trim());
paramList.Add("@DocSubject", txtDocSubject.Text.Trim());
paramList.Add("@DocName", txtDocName.Text.Trim());
paramList.Add("@DocFilePath", serverFilePath);
paramList.Add("@DocComments", txtComments.Text.Trim());
paramList.Add("@DocStatus", ddlDocStatus.Text.Trim());
paramList.Add("@CreatedBy", lblCurrentUser.Text.Trim());
paramList.Add("@CreatedDateTime", DateTime.Now);
paramList.Add("@DocTypeName", ddlDocType.Text.Trim());
paramList.Add("@DocPriority", ddlDocPriority.Text.Trim());
status = objDMS.CRUD_DocumentDetails(paramList);
saveUploadedFiles(operationMode);
if (status && saveFileFlag<=0)
{
//Log File Operation
string FileName = DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
string FilePath = Server.MapPath("~/Logs/" + FileName);
string logDetails = "DocNumber " + txtDocNumber.Text.Trim() + "is created successfully at " + DateTime.Now.ToString();
objLogDetails.CreateLog(logDetails, lblCurrentUser.Text.Trim(), FilePath);
//End Log File Operation
objUI.setTextBoxesAsBlank(this);
lblStatus.Text = "New Document Created Successfully.";
lblStatus.ForeColor = System.Drawing.Color.Green;
btnCreateDocument.Text = "Create Document";
}
else
{
//Log File Operation
string FileName = DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
string FilePath = Server.MapPath("~/Logs/" + FileName);
string logDetails = "DocNumber " + txtDocNumber.Text.Trim() + "saving failed at " + DateTime.Now.ToString();
objLogDetails.CreateLog(logDetails, lblCurrentUser.Text.Trim(), FilePath);
//End Log File Operation
lblStatus.Text = "New Document Saving Failed.";
lblStatus.ForeColor = System.Drawing.Color.Red;
btnCreateDocument.Text = "Create Document";
}
}
else if (btnCreateDocument.Text == "Update Document")
{
btnCreateDocument.Text = "Please Wait...";
paramList = new Hashtable();
operationMode = "EDIT";
paramList.Add("@Mode", "UPDATE");
paramList.Add("@DocNumber", txtDocNumber.Text.Trim());
paramList.Add("@DocSubject", txtDocSubject.Text.Trim());
paramList.Add("@DocName", txtDocName.Text.Trim());
paramList.Add("@DocFilePath", serverFilePath);
paramList.Add("@DocComments", txtComments.Text.Trim());
paramList.Add("@DocStatus", ddlDocStatus.Text.Trim());
paramList.Add("@CreatedBy", lblCurrentUser.Text.Trim());
paramList.Add("@CreatedDateTime", DateTime.Now);
paramList.Add("@DocTypeName", ddlDocType.Text.Trim());
paramList.Add("@DocPriority", ddlDocPriority.Text.Trim());
status = objDMS.CRUD_DocumentDetails(paramList);
saveUploadedFiles(operationMode);
if (status && saveFileFlag <= 0)
{
//Log File Operation
string FileName = DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
string FilePath = Server.MapPath("~/Logs/" + FileName);
string logDetails = "DocNumber " + txtDocNumber.Text.Trim() + "is updated successfully at " + DateTime.Now.ToString();
objLogDetails.CreateLog(logDetails, lblCurrentUser.Text.Trim(), FilePath);
//End Log File Operation
fillDocFileList(txtDocNumber.Text.Trim());
objUI.setTextBoxesAsBlank(this);
lblStatus.Text = " Document Updated Successfully.";
lblStatus.ForeColor = System.Drawing.Color.Green;
btnCreateDocument.Text = "Update Document";
}
else
{
//Log File Operation
string FileName = DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
string FilePath = Server.MapPath("~/Logs/" + FileName);
string logDetails = "DocNumber " + txtDocNumber.Text.Trim() + "Updation failed at " + DateTime.Now.ToString();
objLogDetails.CreateLog(logDetails, lblCurrentUser.Text.Trim(), FilePath);
//End Log File Operation
lblStatus.Text = " Document Updation Failed.";
lblStatus.ForeColor = System.Drawing.Color.Red;
btnCreateDocument.Text = "Update Document";
}
}
}
protected void gvDocFileList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
fileParamList = new Hashtable();
fileParamList.Add("@opMode", "DELETE");
fileParamList.Add("@DocFileID", gvDocFileList.Rows[e.RowIndex].Cells[0].Text.Trim());
fileParamList.Add("@DocID", gvDocFileList.Rows[e.RowIndex].Cells[1].Text.Trim());
fileParamList.Add("@DocFilePath",gvDocFileList.Rows[e.RowIndex].Cells[2].Text.Trim());
fileParamList.Add("@ModifiedBy", lblCurrentUser.Text.Trim());
fileParamList.Add("@ModifiedDT", DateTime.Now);
status = objDMS.CRUD_DocFileDetails(fileParamList);
if (status)
{
fillDocFileList(txtDocNumber.Text.Trim());
//Log File Operation
string FileName = DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
string FilePath = Server.MapPath("~/Logs/" + FileName);
string logDetails = "For the DocNumber " + txtDocNumber.Text.Trim() + "One file is deleted successfully at " + DateTime.Now.ToString();
objLogDetails.CreateLog(logDetails, lblCurrentUser.Text.Trim(), FilePath);
//End Log File Operation
lblStatus.Text = "The Record is Deleted Successfully";
lblStatus.ForeColor = System.Drawing.Color.Green;
}
else
{
fillDocFileList(txtDocNumber.Text.Trim());
lblStatus.Text = "The Record Deletion Failed.";
lblStatus.ForeColor = System.Drawing.Color.Red;
}
}
protected void gvDocFileList_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
fillDocFileList(txtDocNumber.Text.Trim());
}
}
Please help me out from here.
thanks in advance.