This is a migrated thread and some comments may be shown as answers.

[Solved] Not understanding AddAjaxSetting()

4 Answers 413 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 16 Apr 2009, 01:54 PM
I have a page that contains a Panel with a few controls and one that is inherited(btnDownload) from the Master page.
When the btnDownload is clicked, the code is going off and building a Dataset. This Dataset is built on a view which contains 200+ columns with only a few rows of data. I'm converting this data to Excel and saving it on a network location...I'm not displaying any data due to it's size.

The report gets created w/o any problems but the Panel_parameters object is never updated and the LoadingPanel1 is not being turned off.

Is there a way for me to force the object to update after report is downloaded to the network to force it to become updated?

AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, btnDownload, null);              
AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, Panel_Parameters, LoadingPanel1);  
 
          


When I modify my view to only have 10 columns, everything works fine.....

 

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 21 Apr 2009, 02:43 PM
Hello Mike,

Please review the below articles for more information about downloading/uploading files and exporting with RadAjax:

http://www.telerik.com/help/aspnet-ajax/ajxdownload.html
http://www.telerik.com/help/aspnet-ajax/grdexportwithajax.html
http://www.telerik.com/help/aspnet-ajax/upload_uploadingoverview.html

Additionally, if you could send us a runnable code which illustrates the described behavior, this would be of great help in finding a resolution for you. 

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mike
Top achievements
Rank 1
answered on 21 Apr 2009, 03:33 PM
Thanks for the tech notes.

Here is the code:

using System; 
using System.Data; 
using System.Drawing; 
using System.Configuration; 
using System.Collections; 
using System.Globalization; //Used to convert Date/Time to specific culture 
using System.Threading; //Used to manage CultureInfo for current thread 
using System.Text; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using Oracle.DataAccess.Client; 
using Oracle.DataAccess.Types; 
using Telerik.WebControls; 
using WebSupergoo.ABCpdf5; 
using WebSupergoo.ABCpdf5.Objects; 
using WebSupergoo.ABCpdf5.Atoms; 
using System.IO; 
using System.IO.Compression; 
using System.Xml; 
using System.Net; 
 
 
public partial class Reports_SITE_zeus_lds : System.Web.UI.Page 
    #region Variables 
 
    // Standard References 
    DataConvert dc = new DataConvert(); //Used to convert data from one type to another 
    DAL_STD.FacilityInfo FacilityInfo = new DAL_STD.FacilityInfo(); 
    DAL_SITE myProtocols = new DAL_SITE(); 
    DAL_STD.ProductInfo myProductLine = new DAL_STD.ProductInfo(); 
    DAL_STD.UserInfo UserInfo = new DAL_STD.UserInfo(); 
    ControlCalls.Controls_Init Controls_Init = new ControlCalls.Controls_Init(); 
 
    const string REPORT_NAME = "RD&E Zeus Data";  //Store Report Name       
    public string myConnectionString = ConfigurationManager.ConnectionStrings["Facility_Connection"].ToString(); 
    public CultureInfo PlantCulture = new CultureInfo(Thread.CurrentThread.CurrentCulture.ToString()); //Holds the Culture of the Plant selected. 
    public CultureInfo PreferredCulture = new CultureInfo(Thread.CurrentThread.CurrentUICulture.ToString()); //Holds the Culture of the Preferred Language selected. 
    public int intTotalItems = 0;   //Holds the total # items returned 
    public string DefaultFacility = "";     // Holds Default Facility Configuration 
    public string DefaultProduct = "";      // Holds Default Product Configuration 
    public string strCriteria = "";         //Passes the search criteria 
    #region Accessors 
    private RadAjaxManager AjaxMgr 
    { 
        get 
        { 
            return (RadAjaxManager)Master.FindControl("RadAjaxManager1"); 
        } 
    } 
    private Label MessageBox 
    { 
        get 
        { 
            return (Label)Master.FindControl("MessageBox"); 
        } 
    } 
    private AjaxLoadingPanel LoadingPanel1 
    { 
        get 
        { 
            return (AjaxLoadingPanel)Master.FindControl("LoadingPanel1"); 
        } 
    } 
  //  private RadGrid RadGrid1 
   // { 
   //     get 
    //    { 
   //         return (RadGrid)Master.FindControl("RadGrid1"); 
    //    } 
  //  } 
    private Panel Panel_Data 
    { 
        get 
        { 
            return (Panel)Master.FindControl("Panel_Data"); 
        } 
    } 
   // private HtmlTable tblData 
  //  { 
   //     get 
    //    { 
    //        return (HtmlTable)Master.FindControl("tblData"); 
    //    } 
   // } 
    private Panel Panel_Headers 
    { 
        get 
        { 
            return (Panel)Master.FindControl("Panel_Headers"); 
        } 
    } 
    private Label lblReportTitle 
    { 
 
        get 
        { 
            return (Label)Master.FindControl("lblReportTitle"); 
        } 
    } 
    private Label lblTimeStamp 
    { 
 
        get 
        { 
            return (Label)Master.FindControl("lblTimeStamp"); 
        } 
    } 
    private Label lblReportSubTitle 
    { 
 
        get 
        { 
            return (Label)Master.FindControl("lblReportSubTitle"); 
        } 
    } 
    private Label lblTotals 
    { 
 
        get 
        { 
            return (Label)Master.FindControl("lblTotals"); 
        } 
    } 
    private Button btnSubmit 
    { 
 
        get 
        { 
        return (Button)Master.FindControl("btnSubmit"); 
        } 
    } 
 
    private Button btnDownload 
    { 
        get 
        { 
            return (Button)Master.FindControl("btnDownload"); 
        } 
    } 
   // private AjaxLoadingPanel RetrievePanel1 
   // { 
    //    get 
     //   { 
      //      return (AjaxLoadingPanel)Master.FindControl("RetrievePanel1"); 
      //  } 
   // } 
  //  private Button button1 
    //{ 
     //   get { return; } 
    //} 
    #endregion 
    #endregion Variables 
    #region Page-specific Configuration 
 
    //Miscellaneous 
    static public DataTable tblResults = new DataTable(); 
    static public DataSet ds = new DataSet(); 
    protected DataTable dt = new DataTable(); 
     
    protected void Page_Load(object sender, EventArgs e) 
    { 
        #region MultiLanguage Support 
        #endregion MultiLangauge Support 
 
        Panel_Data.Visible = true
        Panel_Headers.Visible = true
 
        Page.MaintainScrollPositionOnPostBack = true
        MessageBox.Text = ""
 
        DataTable dt = new DataTable(); 
 
        if (!Page.IsPostBack) 
        { 
            init_Controls(); 
        } 
 
        // Connect sub-page entities to Master page to capture user responses 
        btnSubmit.Click += new EventHandler(btnSubmit_Click); 
        btnDownload.Click += new EventHandler(btnDownload_Click); 
        //this.RadGrid1.NeedDataSource += new Telerik.WebControls.GridNeedDataSourceEventHandler(this.RadGrid1_NeedDataSource); 
       // this.RadGrid1.ItemDataBound += new Telerik.WebControls.GridItemEventHandler(this.RadGrid1_ItemDataBound); 
 
        CustomGridAttributes(); 
        SetupAjax(); 
 
        btnDownload.Visible = true
        btnSubmit.Visible = false
    } 
 
    private void SetupAjax() 
    { 
        try 
        { 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlFacilities, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlFacilities, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlFacilities, Panel_Data, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlFacilities, ddlProducts, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlFacilities, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlProducts, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlProducts, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlProducts, Panel_Data, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(ddlProducts, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(CallbackRadioButtonList1, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(CallbackRadioButtonList1, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(CallbackRadioButtonList1, Panel_Data, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(CallbackRadioButtonList1, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(lbxProtocolID, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(lbxProtocolID, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(lbxProtocolID, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(lbxProtocolID, Panel_Data, null); 
             
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgRightArrow, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgRightArrow, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgRightArrow, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgRightArrow, Panel_Data, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgLeftArrow, ListBoxTable, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgLeftArrow, btnDownload, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgLeftArrow, Panel_Headers, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgLeftArrow, Panel_Data, null); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(imgHelp, Help, null); 
 
            AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, btnDownload, null);             
            //AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, MessageBox, LoadingPanel1); 
            AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, Panel_Parameters, LoadingPanel1); 
            //AjaxMgr.AjaxSettings.AddAjaxSetting(btnDownload, Panel_Headers, null); 
 
            //AjaxMgr.AjaxSettings.AddAjaxSetting(buton1, Button1, LoadingPanel1); 
        } 
        catch (Exception ew) 
        { 
 
        } 
    } 
    #endregion Page-specific Configuration 
    #region Page Controls 
 
    private void init_Controls() 
    { 
        // Get User Default Facility/Product 
        string user = HttpContext.Current.User.Identity.Name; 
        user = user.Replace(@"\", @"\\"); 
        DataTable dtDefaultConfig = UserInfo.get_user_default_config(user.ToUpper()); 
        if (dtDefaultConfig.Rows.Count > 0) 
        { 
            DefaultFacility = dtDefaultConfig.Rows[0]["DEFAULT_FACILITY"].ToString(); 
            DefaultProduct = dtDefaultConfig.Rows[0]["DEFAULT_PRODUCT"].ToString(); 
        } 
 
        // Initialize Radio button selection list 
        CallbackRadioButtonList1.SelectedIndex = 0; 
 
        // Populate Plant Names 
        ddlFacilities_Populate(); 
        ddlProducts_Populate(); 
 
        // Set StartDate to Today-7         
 
        // Set EndDate to Today 
        //txtEndDate.SelectedDate = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " 18:00"); 
        lbxProtocolID_Populate(); 
         
        lblReportTitle.Text = "RD&E Zeus Data"
    } 
    protected void ddlFacilities_Populate() 
    { 
        ddlFacilities.Items.Clear(); 
 
        DataTable dt = FacilityInfo.get_facilities(); 
        if (dt.Rows.Count > 0) 
        { 
            //ddlFacilities.Rows = dt.Rows.Count; 
            ddlFacilities.DataSource = dt; 
            ddlFacilities.Enabled = true
            ddlFacilities.DataTextField = "FACILITY_DESCRIPTION"
            ddlFacilities.DataValueField = "FACILITY"
            ddlFacilities.DataBind(); 
            DefaultFacility = "RDE"
 
            // Set Default Facility selection 
            if (DefaultFacility != "") { ddlFacilities.SelectedValue = DefaultFacility; } 
        } 
        else 
        { 
            ddlFacilities.Items.Add("No data available"); 
            ddlFacilities.Enabled = false
        } 
    } 
    protected void ddlFacilities_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        if (ddlFacilities.SelectedIndex >= 0) 
        { 
            ddlProducts_Populate(); 
            lbxProtocolID_Populate(); 
 
            lblReportTitle.Text = "RD&E Zeus Data"
 
            //Disable Export Functionality and DataGrid, as well as reset totals and timestamp 
            //tblData.Visible = false; 
            lblTotals.Visible = false
            lblTimeStamp.Visible = false
            btnDownload.Enabled = true
           // RadGrid1.MasterTableView.Controls.Clear(); 
          //  RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
        } 
    } 
 
    protected void ddlProducts_Populate() 
    { 
        ddlProducts.Items.Clear(); 
 
        dt = FacilityInfo.get_products_by_facility(ddlFacilities.SelectedValue); 
 
        if (dt.Rows.Count > 0) 
        { 
            //ddlProducts.Rows = dt.Rows.Count; 
            ddlProducts.DataSource = dt; 
            ddlProducts.Enabled = true
            ddlProducts.DataTextField = "PRODUCT_DESCRIPTION"
            ddlProducts.DataValueField = "PRODUCT"
            ddlProducts.DataBind(); 
            // Set Report Description 
            lblReportTitle.Text = "RD&E Zeus Data"
 
            // Set Default Product selection 
            if (DefaultProduct != "") { ddlProducts.SelectedValue = DefaultProduct; } 
        } 
        else 
        { 
            ddlProducts.Enabled = false
        } 
    } 
    protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        MessageBox.Text = ""
 
        // Set Report Description 
        lblReportTitle.Text = "RD&E Zeus Data"
 
        lbxProtocolID_Populate(); 
         
        //Disable Export Functionality and DataGrid, as well as reset totals and timestamp 
    //    tblData.Visible = false; 
        lblTotals.Visible = false
        lblTimeStamp.Visible = false
        btnDownload.Enabled = true
       // RadGrid1.MasterTableView.Controls.Clear(); 
       // RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
    } 
 
    protected void lbxProtocolID_Populate() 
    { 
        DataTable tblTemp = new DataTable(); 
        lbxSelected.Items.Clear(); 
        lbxProtocolID.Items.Clear(); 
        strCriteria = "PROTOCOLID"
        lbxProtocolID.DataSource = myProtocols.rde_get_zeus_protocols(ddlFacilities.SelectedValue, 
                                                       ddlProducts.SelectedValue); 
 
 
 
        //lbxProtocolID.DataSource = myProductLine.entity_list(ddlFacilities.SelectedValue, 
        //                                             ddlProducts.SelectedValue); 
 
        lbxProtocolID.DataTextField = "PROTOCOLID"
        lbxProtocolID.DataValueField = "rownum"
        lbxProtocolID.DataBind(); 
    } 
     
 
    protected void radByX_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        //Initialize Controls 
        RemoveItems(true); 
        //lbxSelected.Items.Clear(); 
 
        switch (CallbackRadioButtonList1.SelectedValue) 
        { 
            case "PROTOCOLID"
                { 
                    lbxProtocolID.Visible = true;                     
                    lbxSelected.Visible = true
                    imgLeftArrow.Visible = true
                    imgRightArrow.Visible = true
                     
                    // Set Report Description 
                    lblReportTitle.Text = "RD&E Zeus Data"
                    break
                } 
            default
                break
        } 
 
     //   tblData.Visible = false; 
        lblTotals.Visible = false
        lblTimeStamp.Visible = false
        btnDownload.Enabled = true
        //RadGrid1.MasterTableView.Controls.Clear(); 
        //RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
    } 
 
    protected void imgRightArrow_Click(object sender, ImageClickEventArgs e) 
    { 
 
        ListBox theListBox = null
 
        theListBox = lbxProtocolID;               
         
        AddItems(theListBox); 
 
       // if (RadGrid1.Visible) 
     //   { 
       //     tblData.Visible = false; 
       //     lblTotals.Visible = false; 
        //    lblTimeStamp.Visible = false; 
        //    btnDownload.Enabled = true; 
         //   RadGrid1.MasterTableView.Controls.Clear(); 
         //   RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
       // } 
 
    } 
    protected void imgLeftArrow_Click(object sender, ImageClickEventArgs e) 
    { 
        RemoveItems(false); 
 
       // if (RadGrid1.Visible) 
      //  { 
        //    tblData.Visible = false; 
       //     lblTotals.Visible = false; 
       //     lblTimeStamp.Visible = false; 
      //      btnDownload.Enabled = true; 
      //      RadGrid1.MasterTableView.Controls.Clear(); 
      //      RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
      //  } 
    } 
 
    protected void AddItems(ListBox listbox) 
    { 
        ArrayList items = new ArrayList(); 
 
        foreach (ListItem itemToAdd in listbox.Items) 
        { 
            if (itemToAdd.Selected) 
            { 
                items.Add(itemToAdd); 
                lbxSelected.Items.Add(itemToAdd); 
            } 
        } 
 
        foreach (ListItem itemToRemove in items) 
        { 
            listbox.Items.Remove(itemToRemove); 
        } 
 
    } 
 
    protected void RemoveItems(bool clearAll) 
    { 
        ArrayList items = new ArrayList(); 
        ListBox theListBox = null
 
         
            theListBox = lbxProtocolID; 
         
 
        foreach (ListItem itemToAdd in lbxSelected.Items) 
        { 
            if (itemToAdd.Selected || clearAll) 
            { 
                // This code will handle inserting the items back into 
                // the list box in the correct position 
                int index = Convert.ToInt32(itemToAdd.Value); 
                try 
                { 
                    int x = 0; 
                    int y = Convert.ToInt32(theListBox.Items[x].Value); 
                    while (index > y) 
                    { 
                        x++; 
                        y = Convert.ToInt32(theListBox.Items[x].Value); 
                    } 
                    theListBox.Items.Insert(x, itemToAdd); 
 
                } 
                catch (Exception ex) 
                { 
                    theListBox.Items.Add(itemToAdd); 
                } 
 
                items.Add(itemToAdd); 
            } 
        } 
 
        foreach (ListItem itemToRemove in items) 
        { 
            lbxSelected.Items.Remove(itemToRemove); 
        } 
    } 
 
    protected void imgHelp_Click(object sender, ImageClickEventArgs e) 
    { 
        lblHelp.Visible = !lblHelp.Visible; 
    } 
 
    protected void btnSubmit_Click(object sender, System.EventArgs e) 
    { 
        MessageBox.Text = ""
 
        btnSubmit.Enabled = false
        //Validate dates 
        if (!ValidateInput()) 
        { 
            MessageBox.Text = "There was an error building the data.  Please try again."
            return
 
        } 
        else 
        { 
            try 
            { 
               // Session["sDTResults"] = SourceData_Build(); 
                //RadGrid1.DataSource = Session["sDTResults"]; 
               // RadGrid1.DataBind(); 
 
 
                DataSet myDataset = new DataSet(); 
                DataTable myDataTable = SourceData_Build(); 
                myDataset.Tables.Add(myDataTable); 
 
                // Set file location  
                string FileLocation = Server.MapPath("../../Downloads/"); 
                FileLocation = "c:\\"
                string FileExtenstion = ".xls"
 
                dc.ConvertDataSetToExcel(myDataset, @FileLocation, REPORT_NAME.ToString());  
 
            } 
            catch (Exception ex) 
            { 
                string x = ex.Message; 
                MessageBox.Text = "There was an error building the data.  Please try again."
                return
            } 
            finally 
            { 
                lblTimeStamp.Text = "Report Generated: " + System.DateTime.Now.ToLongDateString() + " at " + System.DateTime.Now.ToShortTimeString(); 
                lblTimeStamp.Font.Bold = true
                lblTimeStamp.ForeColor = Color.Orange; 
                lblTimeStamp.Visible = true
            } 
            return
 
            //Enable Export Functionality and DataGrid and display Time Stamp             
            btnSubmit.Enabled = false
        } 
    } 
 
 
    protected void btnDownload_Click(object sender, System.EventArgs e) 
    { 
        MessageBox.Text = ""
        string result = "0"
 
        //Validate dates 
        if (!ValidateInput()) 
        { 
 
        } 
        else 
        { 
            try 
            { 
                DataSet myDataset = new DataSet(); 
                DataTable myDataTable = SourceData_Build(); 
                myDataset.Tables.Add(myDataTable); 
                myDataset.Dispose(); 
                 
 
                // Set file location  
                //string FileLocation = Server.MapPath("..\\..\\Downloads/"); 
                string FileLocation = "\\\\blfsrocrdc02\\roc_rd\\public\\WebReports\\"
                string FileExtenstion = ".xls"
 
                // Check # of rows returned by Query, if greater than 65,000 convert to XML 
                //This report should not return that many rows. 
                long rows = myDataTable.Rows.Count; 
               /* if (rows > 60000)
                {
                    string strDSResults = String.Empty;
                    XmlDocument xmlDoc = new XmlDocument();
                    FileStream fs = new FileStream(@FileLocation + REPORT_NAME.ToString() + ".gz", FileMode.Create, FileAccess.Write);
                    GZipStream ZipStream = new GZipStream(fs, CompressionMode.Compress, false);
                    // Convert data to XML format, Compress the file and save to local drive
                    myDataset.WriteXml(ZipStream);
                    ZipStream.Close();
                    fs.Close();
                    // Update File type to download
                    FileExtenstion = ".gz";
                }
                // Pass the Dataset to the DataConvert Object and convert it to Excel then initiate Download
                else { */ 
                 
                 
                dc.ConvertDataSetToExcel(myDataset, @FileLocation, REPORT_NAME.ToString());  
                //} 
 
 
                //StringBuilder sb = new StringBuilder(); 
                //sb.Append("<script>"); 
                //sb.Append("window.open('" + "http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion + "', '', '');"); 
                //sb.Append("</scri"); 
                //sb.Append("pt>"); 
 
                //Page.RegisterStartupScript("test", sb.ToString()); 
 
                H1.Visible = true
                H1.NavigateUrl = "http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion; 
                //H1.NavigateUrl = "\\blfsrocrdc02\roc_rd\public\WebReports\ + REPORT_NAME.ToString() + FileExtenstion; 
 
                //Response.RedirectLocation = "http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion; 
                //WebClient Client = new WebClient(); 
                //Client.DownloadFile("http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion, "c:/" + REPORT_NAME.ToString() + FileExtenstion);  
 
            } 
            catch (Exception ex) 
            { 
                string ErrorMsg = ex.Message; 
                MessageBox.Text = ErrorMsg; 
                return
            } 
            finally 
            { 
                if (result != "0")
                { MessageBox.Text = result; }
                else
                {
                    lblTimeStamp.Text = "Report Downloaded: " + System.DateTime.Now.ToLongDateString() + " at " + System.DateTime.Now.ToShortTimeString();
                    Panel_Parameters.Dispose();                    
                    
                   // lblTimeStamp.Font.Bold = true;
                    //lblTimeStamp.ForeColor = Color.Orange;
                   // lblTimeStamp.Visible = true;
                }
            }            
            btnDownload.Enabled = false;
        }
        //Enable Export Functionality and DataGrid and display Time Stamp
        //lblTimeStamp.Visible = true;
        //tblData.Visible = false;
        btnSubmit.Enabled = false;
    }
    #endregion Page Controls
    #region Data Collection & Calculations
    private DataTable SourceData_Build()
    {
        //Generate Parameter list of Entities to query
        string sParams = ""; 
 
        foreach (ListItem item in lbxSelected.Items) 
       { 
           sParams += "'" + item.Text + "',";
       }
       
        sParams = sParams.Substring(0, sParams.Length - 1); //Trim off last comma                      
       
        return myProtocols.rde_get_zeus_lds(ddlFacilities.SelectedValue,
                                          ddlProducts.SelectedValue,
                                          CallbackRadioButtonList1.SelectedValue,
                                          sParams);
    }
    public bool ValidateInput()
    {
        /************************************************************************
        * Function: ValidateInput
        * Author: Charlie Hart
        * Input: None
        * Output: None
        * Description: Function to check that all input fields have valid data.
        ************************************************************************/
        bool isValid = true;
        /*bool isValidSelection = true;
        long start = 0;
        long end = 0;
        try
        {
            start = txtStartDate.SelectedDate.ToFileTime();
            end = txtEndDate.SelectedDate.ToFileTime();
        }
        catch (Exception ex)
        {
            isValidSelection = false;
        }
        
        if (!isValidDate)
        {
            MessageBox.Text = "Please select valid dates from the calendar menus.";
        }
        else if (end <= start)
        {
            MessageBox.Text = "Please select a start date earlier than the end date.";
        }
        else if (ddlFacilities.SelectedItem.Text == "<Select>" ||
         ddlFacilities.SelectedValue == "") 
        { 
            MessageBox.Text = "Please select a value for Facility.";
        }
        else
        {
            isValid = true;
        }*/
        return isValid;
    }
    #endregion Data Collection & Calculations
    #region Grids
   // protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    //{
      //  if (Page.IsPostBack || Page.IsCallback)
     //       RadGrid1.DataSource = Session["sDTResults"];
    //}
   // private void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
   // {
   //     if (e.Item is GridDataItem)
    //    {
    //        intTotalItems += 1;
    //    }
   //     lblTotals.Visible = true;
      //  lblTotals.Text = "Items Returned: " + intTotalItems;
   // }
    private void CustomGridAttributes()
    {
    }
    #endregion Grids
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Enabled = false;
        MessageBox.Text = ""; 
        string result = "0";
        //Validate dates
        if (!ValidateInput())
        {
        }
        else
        {
            try
            {
                DataSet myDataset = new DataSet();
                DataTable myDataTable = SourceData_Build();
                myDataset.Tables.Add(myDataTable);
                // Set file location 
                //string FileLocation = Server.MapPath("..\\..\\Downloads/");
                string FileLocation = "\\\\blfsrocrdc02\\roc_rd\\public\\WebReports\\";
                string FileExtenstion = ".xls";
             
                dc.ConvertDataSetToExcel(myDataset, @FileLocation, REPORT_NAME.ToString());
              
                H1.Visible = true;
                H1.NavigateUrl = "http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion; 
                //H1.NavigateUrl = "\\blfsrocrdc02\roc_rd\public\WebReports\ + REPORT_NAME.ToString() + FileExtenstion; 
 
                //Response.RedirectLocation = "http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion; 
                //WebClient Client = new WebClient(); 
                //Client.DownloadFile("http://camsreports/downloads/" + REPORT_NAME.ToString() + FileExtenstion, "c:/" + REPORT_NAME.ToString() + FileExtenstion);  
 
            } 
            catch (Exception ex) 
            { 
                string ErrorMsg = ex.Message; 
                MessageBox.Text = ErrorMsg; 
                return
            } 
            finally 
            { 
                if (result != "0"
                { MessageBox.Text = result; } 
                else 
                { 
                    lblTimeStamp.Text = "Report Downloaded: " + System.DateTime.Now.ToLongDateString() + " at " + System.DateTime.Now.ToShortTimeString(); 
                    lblTimeStamp.Font.Bold = true
                    lblTimeStamp.ForeColor = Color.Orange; 
                    lblTimeStamp.Visible = true
                } 
            } 
            LoadingPanel1.Dispose(); 
            btnDownload.Enabled = false
        }         
 
    } 





0
Mike
Top achievements
Rank 1
answered on 23 Apr 2009, 05:30 PM
Thanks again for the files.

I do not appear to be exporting to Excel in the same manner as outlined in the those docs...

Any feedback on the code?
0
Iana Tsolova
Telerik team
answered on 24 Apr 2009, 11:35 AM
Hello Mike,

I went through your code and could not find anything disturbing in it, it looks fine to me. The LoadingPanel should be displayed over the Panel_Parameters through the report generation process.
However, can you confirm that the btnDownload only generates the report but provides the real file to the user? Because if it is sending the file directly, you should disable ajax during downloading as show in the previously provided links.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
Mike
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Mike
Top achievements
Rank 1
Share this question
or