Hi all,
Using UI for ASP.NET AJAX Q3 2015 along with VS 2013. I am using below link as a prototype.
http://demos.telerik.com/aspnet-ajax/asyncupload/examples/validation/defaultcs.aspx
I modified it to fit my requirements. I would like to use RadAjaxLoadingPanel and RadAsyncUpload together on the button click event of the below button (attached AsyncUpload - Validation.png)
<telerik:RadButton runat="server" Skin="Silk" ID="BtnSubmit"Text="Validate the uploaded files" OnClick="BtnSubmit_Click"></telerik:RadButton>
On Button Click event, the routine uploads the file as well as runs SQL Stored procedure and on return Stored procedure also executes SSIS packages.
The whole process takes some 5-7 minutes that is the main reason I would like to display the Loading Panel during the execution phase. Instead of IE “Waiting for Local host” message. If I do use RadAjaxLoadingPanel, after the process complete, current form stays open, does not go to attached 2nd screen (Attachment 2.png).
Below is my complete code. Thanks for any help
Gc_0620
_________
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'><head runat="server"> <title>Telerik ASP.NET Example</title> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="scripts.js"></script></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> function rAsyncUpload_Selected(sender, args) { var currentFileName = args.get_fileName(); document.getElementById('<%=hidValueFileName.ClientID %>').value = currentFileName; } function OnClientFileUploadRemoved(sender, args) { var currentFileName = args.get_fileName(); // alert(currentFileName); //OnClientFileUploadRemoved document.getElementById('<%=hidValueFileName.ClientID %>').value = ""; __doPostBack("<%= RefreshButton.UniqueID %>", "OnClick"); } </script> </telerik:RadCodeBlock> <div class="demo-container size-medium"> <div class="qsf-demo-canvas"> <h2>Upload your files</h2> <ul class="qsf-list"> <li> <strong>Allowed file types:</strong> jpg, jpeg, png, gif,csv (client-side validation). </li> <li> <strong>Allowed overall upload size:</strong> 100 MB (server-side validation). </li> </ul> <table> <tr id="in_put" runat="server"> <td> <telerik:RadMonthYearPicker ID="RadMonthYearPicker1" AutoPostBack="true" OnSelectedDateChanged="btnPopulate_Form" runat="server"> </telerik:RadMonthYearPicker> </td> <td> <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" AllowedFileExtensions="jpg,jpeg,png,gif,csv" TargetFolder="" MultipleFileSelection="Automatic" OnClientFileSelected="rAsyncUpload_Selected" PostbackTriggers="BtnSubmit" MaxFileSize="100971520" Skin="Silk" OnClientFileUploadRemoved="OnClientFileUploadRemoved" UploadedFilesRendering="BelowFileInput"> </telerik:RadAsyncUpload> </td> </tr> </table> <div class="qsf-results"> <telerik:RadButton runat="server" Skin="Silk" ID="BtnSubmit" Text="Validate the uploaded files" OnClick="BtnSubmit_Click"> </telerik:RadButton> <asp:Panel ID="ValidFiles" Visible="false" runat="server" CssClass="qsf-success"> <h3>You successfully uploaded:</h3> <ul class="qsf-list" runat="server" id="ValidFilesList"></ul> </asp:Panel> <asp:Panel ID="InvalidFiles" Visible="false" runat="server" CssClass="qsf-error"> <h3>The Upload failed for:</h3> <ul class="qsf-list ruError" runat="server" id="InValidFilesList"> <li> <p class="ruErrorMessage">The size of your overall upload exceeded the maximum of 1 MB</p> </li> </ul> </asp:Panel> <telerik:RadButton Skin="Silk" ID="RefreshButton" runat="server" OnClick="RefreshButton_Click" Visible="false" Text="Back"></telerik:RadButton> </div> <div class="qsf-decoration"></div> </div> <script type="text/javascript"> //<![CDATA[ Sys.Application.add_load(function () { demo.initialize(); }); //]]> </script> <table> <tr> <td class="hiddentd_width"> <asp:HiddenField ID="hidValueFileName" runat="server" /> </td> <td class="hiddentd_width"> <asp:HiddenField runat="server" ID="hiddendmonth" Value="" /> </td> <td class="hiddentd_width"> <asp:HiddenField runat="server" ID="hdnstartdate" Value="" /> </td> <td class="hiddentd_width"> <asp:HiddenField runat="server" ID="hdnenddate" Value="" /> </td> <td class="hiddentd_width"> <asp:HiddenField runat="server" ID="hdncurrentfy" Value="" /> </td> <td class="hiddentd_width"> <asp:HiddenField runat="server" ID="hdnnexteffectivedate" Value="" /> </td> </tr> <tr> <td> <asp:HiddenField runat="server" ID="hdnCurrentFiscalYear_st_dt" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnNextFiscalYear_st_dt" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnCurrentMonthFile" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnNextMonthFile" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnEndCurrentMonthFile" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnBegNextMonthFile" Value="" /> </td> </tr> <tr> <td> <asp:HiddenField runat="server" ID="HiddenFiscalYear" Value="" /> </td> <td> <asp:HiddenField runat="server" ID="hdnFolderCreated" Value="" /> </td> <td> <telerik:RadToolTip runat="server" ID="tooltip1" TargetControlID="ClientID" IsClientID="true" Animation="FlyIn" Skin="WebBlue" OffsetX="35" EnableRoundedCorners="true" EnableShadow="true" RelativeTo="Element" AnimationDuration="2000" ShowDelay="500" RenderInPageRoot="true" Position="TopRight"> </telerik:RadToolTip> </td> </tr> </table> </div> </form></body></html>
using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Configuration;using System.Web.Security;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using Telerik.Web.UI;using System.Collections;using System.Drawing;using System.Text.RegularExpressions;using System.Data.SqlClient;using System.IO;namespace WebApplication1{ public partial class WebForm1 : System.Web.UI.Page { const int MaxTotalBytes = 1048576; // 1 MB long totalBytes; public static string connectionString = ConfigurationManager.ConnectionStrings["my-ConnectionString"].ToString(); public SqlConnection sqlConnection = new SqlConnection(connectionString); //Declare a global SqlDataAdapter SqlDataAdapter public SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); //Declare a global SqlCommand SqlCommand public SqlCommand sqlCommand = new SqlCommand(); // SqlString a = new SqlString(); public static string Tempstr, Tempstr1, message, cleanMessage, global_export_folder, updatedDataKey, folderpath = string.Empty; protected void Page_Load(object sender, EventArgs e) { } public void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e) { /* BtnSubmit.Visible = false; RefreshButton.Visible = true; RadAsyncUpload1.Visible = false; var liItem = new HtmlGenericControl("li"); liItem.InnerText = e.File.FileName; if (totalBytes < MaxTotalBytes) { // Total bytes limit has not been reached, accept the file e.IsValid = true; totalBytes += e.File.ContentLength; } else { // Limit reached, discard the file e.IsValid = false; } if (e.IsValid) { ValidFiles.Visible = true; ValidFilesList.Controls.AddAt(0, liItem); } else { InvalidFiles.Visible = true; InValidFilesList.Controls.AddAt(0, liItem); } */ } protected void RefreshButton_Click(object sender, EventArgs e) { Page.Response.Redirect(Request.RawUrl); } protected void btnPopulate_Form(object sender, EventArgs e) { if (RadMonthYearPicker1.DbSelectedDate == null) { hiddendmonth.Value = ""; // RadAjaxPanel1.ResponseScripts.Add(string.Format("alert('- Reporting Month is required!!!');")); return; } if (RadMonthYearPicker1.SelectedDate.Value >= DateTime.Now) { // RadAjaxPanel1.ResponseScripts.Add(string.Format("alert('- Can't be future date!');")); // return; } // Tempstr = RadMonthYearPicker1.DbSelectedDate.ToString(); // Tempstr1 = Tempstr; string startmonth_year = RadMonthYearPicker1.SelectedDate.Value.Month.ToString() + " , " + RadMonthYearPicker1.SelectedDate.Value.Year.ToString(); DateTime selectedDate = RadMonthYearPicker1.SelectedDate.Value; DateTime startDate = selectedDate.AddDays((selectedDate.Day - 1) * -1); DateTime endDate = startDate.AddDays(DateTime.DaysInMonth(startDate.Year, startDate.Month) - 1); string dtselectedyear = RadMonthYearPicker1.SelectedDate.Value.Year.ToString(); DateTime NextMonthEffectiveDate = endDate.AddDays(+1); // int PreviousYear = (RadMonthYearPicker1.SelectedDate.Value.Year - 1); int NextYear = (RadMonthYearPicker1.SelectedDate.Value.Year + 1); string CurrentFiscalYear_st_dt, NextFiscalYear_st_dt = null; string month_selected = string.Empty; string currentmonth = string.Empty; string nextmonth = string.Empty; switch (RadMonthYearPicker1.SelectedDate.Value.Month.ToString()) { case "1": month_selected = "January"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "01E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "02B"; break; case "2": month_selected = "February"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "02E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "03B"; break; case "3": month_selected = "March"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "03E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "04B"; break; case "4": month_selected = "April"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "04E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "05B"; break; case "5": month_selected = "May"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "05E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "06B"; break; case "6": month_selected = "June"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "06E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "07B"; break; case "7": month_selected = "July"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "07E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "08B"; break; case "8": month_selected = "August"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "08E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "09B"; break; case "9": month_selected = "September"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "09E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "10B"; break; case "10": month_selected = "October"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "10E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "11B"; break; case "11": month_selected = "November"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "11E"; nextmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "12B"; break; case "12": month_selected = "December"; currentmonth = dtselectedyear.Substring(dtselectedyear.Length - 2) + "12E"; nextmonth = NextYear.ToString().Substring(NextYear.ToString().Length - 2) + "01B"; break; default: break; } if (RadMonthYearPicker1.SelectedDate.Value.Month <= 6) { CurrentFiscalYear_st_dt = "07/01/" + (RadMonthYearPicker1.SelectedDate.Value.Year - 1).ToString(); NextFiscalYear_st_dt = "07/01/" + (RadMonthYearPicker1.SelectedDate.Value.Year).ToString(); } else { CurrentFiscalYear_st_dt = "07/01/" + (RadMonthYearPicker1.SelectedDate.Value.Year).ToString(); NextFiscalYear_st_dt = "07/01/" + (RadMonthYearPicker1.SelectedDate.Value.Year + 1); //NextYear.ToString(); } hiddendmonth.Value = month_selected.ToString(); hdnstartdate.Value = startDate.ToShortDateString(); hdnenddate.Value = endDate.ToShortDateString(); hdncurrentfy.Value = NextFiscalYear_st_dt.Substring(NextFiscalYear_st_dt.ToString().Length - 4); // Until June, Selected year of date. // Higher than june, Selected year+1 hdnnexteffectivedate.Value = NextMonthEffectiveDate.ToShortDateString(); hdnNextFiscalYear_st_dt.Value = NextFiscalYear_st_dt.ToString(); hdnCurrentFiscalYear_st_dt.Value = CurrentFiscalYear_st_dt.ToString(); hdnCurrentMonthFile.Value = currentmonth.ToString(); hdnNextMonthFile.Value = nextmonth.ToString(); hdnEndCurrentMonthFile.Value = month_selected.ToString() + ' ' + RadMonthYearPicker1.SelectedDate.Value.Year.ToString(); if (RadMonthYearPicker1.SelectedDate.Value.Month == 12) { hdnBegNextMonthFile.Value = "January" + ' ' + (RadMonthYearPicker1.SelectedDate.Value.Year + 1).ToString(); Tempstr = "January" + ' ' + (RadMonthYearPicker1.SelectedDate.Value.Year + 1).ToString(); Tempstr1 = Tempstr; } else { hdnBegNextMonthFile.Value = NextMonthEffectiveDate.ToString("MMMM") + ' ' + RadMonthYearPicker1.SelectedDate.Value.Year.ToString(); Tempstr1 = Tempstr; } Tempstr = "Current FY Start Dt: " + CurrentFiscalYear_st_dt + " Next FY Start Dt: " + NextFiscalYear_st_dt + " Hidden FY: " + hdncurrentfy.Value; Tempstr1 = Tempstr; } protected void BtnSubmit_Click(object sender, System.EventArgs e) { // ValidationInput.Text = string.Empty; if (RadMonthYearPicker1.SelectedDate >= DateTime.Now || RadAsyncUpload1.UploadedFiles.Count == 0) { return; } else { if (RadMonthYearPicker1.SelectedDate.Value.Month <= 9) // if (RadMonthYearPicker1.SelectedDate.Value.Month.ToString().Length < 2) { folderpath = "0" + RadMonthYearPicker1.SelectedDate.Value.Month.ToString(); } else { folderpath = RadMonthYearPicker1.SelectedDate.Value.Month.ToString(); } string tempfolderpath = hdnCurrentFiscalYear_st_dt.Value.Substring(hdnCurrentFiscalYear_st_dt.Value.ToString().Length - 4) + "\\"; Tempstr = tempfolderpath; Tempstr1 = Tempstr; folderpath = "FY" + hdncurrentfy.Value + "\\" + hdncurrentfy.Value + '-' + folderpath + ' ' + hiddendmonth.Value; Tempstr = folderpath; Tempstr1 = Tempstr; sqlCommand = new SqlCommand("Import_Source_File", sqlConnection); sqlCommand.Parameters.AddWithValue("@FolderName", folderpath.ToString().Trim()); sqlCommand.Parameters.AddWithValue("@runtype", "1"); var outParam = new SqlParameter("@FolderCreated", SqlDbType.VarChar); outParam.Direction = ParameterDirection.Output; outParam.Size = 4000; sqlCommand.Parameters.Add(outParam); // sqlCommand.Parameters.@FolderCreated.size = 2000; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 7200; sqlConnection.Open(); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); var folder = Path.GetDirectoryName(outParam.Value.ToString().Trim()) + "\\"; hdnFolderCreated.Value = "All files are created into Network Folder: " + folder; global_export_folder = folder; Tempstr = folder; Tempstr1 = Tempstr; sqlConnection.Close(); RadAsyncUpload1.TargetFolder = global_export_folder; string path = RadAsyncUpload1.TargetFolder; string file_name = hiddendmonth.Value.ToString(); foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles) { file.SaveAs(Path.Combine((path), hidValueFileName.Value.ToString())); // + file.GetExtension())); } string destfileextension = System.IO.Path.GetExtension(hidValueFileName.Value.ToString().Trim()); string destfile_w_outextension = hidValueFileName.Value.ToString().Trim().Substring(0, hidValueFileName.Value.ToString().Trim().Length - destfileextension.Length); sqlCommand = new SqlCommand("Import_Source_File", sqlConnection); sqlCommand.Parameters.AddWithValue("@FolderName", global_export_folder.ToString()); sqlCommand.Parameters.AddWithValue("@runtype", "2"); sqlCommand.Parameters.AddWithValue("@SourcefileName", destfile_w_outextension.ToString().Trim()); sqlCommand.Parameters.AddWithValue("@SourceCSVfileName", hidValueFileName.Value.ToString().Trim()); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 7200; sqlConnection.Open(); Tempstr = "Global Export Folder: " + global_export_folder.ToString() + " Folder: " + folder.ToString().Trim(); Tempstr += " File Name with extension: " + hidValueFileName.Value.ToString().Trim() + " File Name w/o extension: " + destfile_w_outextension.ToString().Trim(); sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); if (sqlConnection.State == ConnectionState.Open) { Tempstr = "Connection Open"; } else { Tempstr = "Connection Close"; } sqlConnection.Close(); // Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "disp_confirm();", true); BtnSubmit.Visible = false; RefreshButton.Visible = true; in_put.Visible = false; // RadMonthYearPicker1.Visible = false; BtnSubmit.Visible = false; RefreshButton.Visible = true; RefreshButton.Text = "Return"; RadAsyncUpload1.Visible = false; } } }}