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

Trying to invoke progress bar / ajax loading panel from child content area page.

1 Answer 114 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Lars
Top achievements
Rank 1
Lars asked on 24 Jan 2012, 07:50 PM
Hi,

We are trying to achieve the following goal: Invoke a RAD Progress Bar (located in a master page) from a child content-area page *while at the same time* disabling all of the screen content in the pnlMainZoneId control in the master page (IE: showing the ajax hourglass) except for the progress bar & its cancel button. When either the progress bar is complete or the cancel button is clicked, we want the ajax hourglass to go away and all of the screen controls to be re-enabled.

I have been trying to implement the following article: http://www.telerik.com/help/aspnet-ajax/ajax-masterpage-update-everywhere.html

...however, I am getting an exception "object not set to an instance..." when reaching this line: ajaxMgr.AjaxSettings.AddAjaxSetting(object1, object2);

Could someone please give me a bit of direction? I have confirmed that the ajaxMgr, object1 and object2 are all correctly instantiated and populated, so I'm not sure where the error is coming from.

I have attached a sample of the pages we are using to replicate the error, below. Please let me know if I can provide more information. Thank you!

Lars


[TEST.MASTER]

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="test.master.cs" Inherits="AutoAAP.test1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<html>
    <head runat="server">
        <title></title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form2" runat="server" style="height: 100%;">
        
            <telerik:RadScriptBlock runat="Server" ID="RadScriptBlock1">
            <script type="text/javascript">                     
                function handleProgressBarUpdateFromServer(sender, args)
                {
                    if ((args.get_progressData() && args.get_progressData().OperationComplete == 'true'))
                    {
                        args.set_cancel(true);                       
                    }
                }                                        
            </script>
            </telerik:RadScriptBlock>

            <telerik:RadAjaxManager ID="RadAjaxManagerMain" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadAjaxManagerMain">
                        <UpdatedControls><telerik:AjaxUpdatedControl ControlID="pnlMainZoneId" LoadingPanelID="RadAjaxLoadingPanelMain" /></UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>

            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanelMain" runat="server" />
            <telerik:RadScriptManager ID="ScriptManager" runat="server" EnableTheming="True" ></telerik:RadScriptManager>

            <asp:Panel ID="divUniversalProgressBar" runat="server">        
                <telerik:RadProgressManager id="MasterRadProgressManager1" runat="server" />
                <telerik:RadProgressArea RegisterWithScriptManager="true" id="MasterRadProgressArea1" runat="server" DisplayCancelButton="true" OnClientProgressUpdating="handleProgressBarUpdateFromServer" />        
            </asp:Panel>

            <asp:Panel ID="pnlMainZoneId" runat="server" Height="100%" Width="100%" >            
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </asp:Panel>

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



[TEST.MASTER.CS]

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Global;
using AutoAAP.StateManagement;
using System.Collections.Generic;
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;

namespace AutoAAP
{
    public partial class test1 : System.Web.UI.MasterPage
    {



        #region Page Events

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #endregion



        #region Progress bar subsystem.
    
        public struct ProgressBarConfig
        {
            public string dialogHeaderText;
            public string cancelText;
            public string elapsedTimeText;
            public string estimatedTimeText;
            public string totalText;
            public string totalFilesText;
            public string transferSpeedText;
            public string uploadedFilesText;
            public bool showProgressBar;
        }
        static public ProgressBarConfig ProgressBarConfiguration = new ProgressBarConfig();

        private void pbPause()
        {
            // Server wait 4 seconds after sending an update.
            // Since browser checks for progress every 3 seconds, should always receive updates.
            System.Threading.Thread.Sleep(new TimeSpan(0, 0, 4));
        }
        private bool pbIsNullOrEmptyString(string sArg)
        {
            bool ret = false;

            if (sArg == null)
            {
                ret = true;
            }
            else if (sArg == string.Empty)
            {
                ret = true;
            }
            else
            {
            }

            return ret;
        }

        /// <summary>
        /// Pass in NULL for strings if you want to hide those fields.
        /// </summary>
        public void ProgressBarConfigure(
        string dialogHeaderText, string cancelText, string elapsedTimeText, string estimatedTimeText,
        string totalText, string totalFilesText, string transferSpeedText, bool showProgressBar)
        {
            ProgressBarConfiguration                            = new ProgressBarConfig();
            ProgressBarConfiguration.dialogHeaderText           = dialogHeaderText;
            ProgressBarConfiguration.cancelText                 = cancelText;
            ProgressBarConfiguration.elapsedTimeText            = elapsedTimeText;
            ProgressBarConfiguration.estimatedTimeText          = estimatedTimeText;
            ProgressBarConfiguration.totalText                  = totalText;
            ProgressBarConfiguration.totalFilesText             = totalFilesText;
            ProgressBarConfiguration.transferSpeedText          = transferSpeedText;
            ProgressBarConfiguration.uploadedFilesText          = "?2Please wait... ";
            ProgressBarConfiguration.showProgressBar            = showProgressBar;

            ProgressBarReset();
        }
        public void ProgressBarReset()
        {
            MasterRadProgressArea1.HeaderText                       = ProgressBarConfiguration.dialogHeaderText;

            ProgressIndicators indicators                           = ProgressIndicators.None;

            MasterRadProgressArea1.Localization.Cancel              = ProgressBarConfiguration.cancelText;
            MasterRadProgressArea1.DisplayCancelButton              = !(pbIsNullOrEmptyString(ProgressBarConfiguration.cancelText));

            MasterRadProgressArea1.Localization.CurrentFileName = "";
            indicators |= ProgressIndicators.CurrentFileName;

            MasterRadProgressArea1.Localization.ElapsedTime         = ProgressBarConfiguration.elapsedTimeText;
            if (!pbIsNullOrEmptyString(ProgressBarConfiguration.elapsedTimeText))
                indicators |= ProgressIndicators.TimeElapsed;

            MasterRadProgressArea1.Localization.EstimatedTime       = ProgressBarConfiguration.estimatedTimeText;
            if (!pbIsNullOrEmptyString(ProgressBarConfiguration.estimatedTimeText))
                indicators |= ProgressIndicators.TimeEstimated;

            MasterRadProgressArea1.Localization.Total               = ProgressBarConfiguration.totalText;
            if (!pbIsNullOrEmptyString(ProgressBarConfiguration.totalText))
                indicators |= ProgressIndicators.TotalProgress;

            MasterRadProgressArea1.Localization.TotalFiles          = ProgressBarConfiguration.totalFilesText;
            if (!pbIsNullOrEmptyString(ProgressBarConfiguration.totalFilesText))
            {
                indicators |= ProgressIndicators.FilesCount;
                indicators |= ProgressIndicators.SelectedFilesCount;
                indicators |= ProgressIndicators.FilesCountBar;
                indicators |= ProgressIndicators.FilesCountPercent;
            }

            MasterRadProgressArea1.Localization.TransferSpeed       = ProgressBarConfiguration.transferSpeedText;
            if (!pbIsNullOrEmptyString(ProgressBarConfiguration.transferSpeedText))
                indicators |= ProgressIndicators.TransferSpeed;

            MasterRadProgressArea1.Localization.Uploaded            = "Please wait...";
            MasterRadProgressArea1.Localization.UploadedFiles       = ProgressBarConfiguration.uploadedFilesText;
                       
            if (ProgressBarConfiguration.showProgressBar)
            {
                indicators |= ProgressIndicators.TotalProgressBar;
                indicators |= ProgressIndicators.TotalProgressPercent;
            }
            
            MasterRadProgressArea1.ProgressIndicators               = indicators;
        }
        public void ProgressBarUpdate(string stepDescription, int stepNumber, int totalSteps)
        {
            // If someone does not pass in a description we
            // will do our best to create one for the end user.
            if (pbIsNullOrEmptyString(stepDescription))
            {
                stepDescription =
                    (stepNumber == 0)
                        ? "Initializing..."
                    : (stepNumber == totalSteps)
                        ? "Completing..."
                        : string.Format("Step {0} of {1}...", stepNumber, totalSteps);
            }

            // Can only update the RadProgressContext, the MasterRadProgressArea1
            // is NOT manipulatable after the ProgressBar appears in the UI. Must
            // cancel the ProgressBar first.
            RadProgressContext progress                             = RadProgressContext.Current;
            progress.OperationComplete                              = false;
            progress.CurrentOperationText                           = stepDescription;
          
            progress.PrimaryTotal                                   = stepNumber;
            progress.PrimaryValue                                   = totalSteps;
            progress.PrimaryPercent                                 = Math.Round(100m * ((totalSteps > 0) ? (stepNumber/(decimal)totalSteps) : 0), 0);

            if (stepNumber >= totalSteps)
            {
                progress.PrimaryTotal                               = totalSteps;
                progress.PrimaryValue                               = totalSteps;
                progress.PrimaryPercent                             = 100;

                pbPause(); // This 4 second pause gives the UI time to poll (every 3 seconds) for text / presentation changes.
                progress.OperationComplete                          = true;
            }
            else
            {
                progress.OperationComplete                          = false;
                pbPause(); // This 4 second pause gives the UI time to poll (every 3 seconds) for text / presentation changes.
            }
        }
        public void ProgressBarHideNow()
        {
            ProgressBarUpdate("Cancelled. Cleaning up...", 0, 0);
        }

    #endregion


   }
}



[TEST.ASPX]

<%@ Page Title="" Language="C#" MasterPageFile="~/test.Master" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="AutoAAP.test" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <p>We are testing the invocation of the master page's progress dialog from a content page.</p>

   
    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btnBeginUpdates">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="divUniversalProgressBar" LoadingPanelID="pnlMainZoneId" />
                    <telerik:AjaxUpdatedControl ControlID="MasterRadProgressManager1" LoadingPanelID="pnlMainZoneId" />
                    <telerik:AjaxUpdatedControl ControlID="MasterRadProgressArea1" LoadingPanelID="pnlMainZoneId" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>


    <asp:Panel ID="pnlButtons" runat="server">
        <asp:Button ID="btnBeginUpdates" runat="server" Text="Test Progress Bar" onclick="btnBeginUpdates_Click" />
    </asp:Panel>

</asp:Content>


[TEST.ASPX.CS]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;

namespace AutoAAP
{
    public partial class test : System.Web.UI.Page
    {

        static private int _curStep = 0;
        static private int _maxStep = 4;
        static private bool _cancelled = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                setupProgressBar(); // When this page is first rendered we need to call "resetProgressBar()" if we are going to use the progress bar on this page.


                RadAjaxManager ajaxMgr      = RadAjaxManager.GetCurrent(Page); //(RadAjaxManager)this.Master.FindControl("RadAjaxManagerMain");
                RadAjaxLoadingPanel pLoad   = (RadAjaxLoadingPanel)this.Master.FindControl("RadAjaxLoadingPanelMain"); //pnlMainZoneId                
                    
                Panel p1                                = (Panel)this.Master.FindControl("divUniversalProgressBar");
                RadProgressManager pRadProgressManager  = (RadProgressManager)this.Master.FindControl("MasterRadProgressManager1");
                RadProgressArea pRadProgressArea        = (RadProgressArea)this.Master.FindControl("MasterRadProgressArea1");


// These statements all throw errors, do not know why!

                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, p1); }
                catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }

                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, pRadProgressManager); }
                catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }

                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, pRadProgressArea); }
                catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }


                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, p1, pLoad); }
                catch (Exception ex) {System.Diagnostics.Debug.Print(ex.Message); }

                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, pRadProgressManager, pLoad); }
                catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message);}

                try { ajaxMgr.AjaxSettings.AddAjaxSetting(btnBeginUpdates, pRadProgressArea, pLoad); }
                catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message);}



            }
        }


        private AutoAAP.test1 getMaster()
        {
            return ((AutoAAP.test1)this.Master);
        }

        private void setupProgressBar()
        {
            _curStep = 0;
            _cancelled = false;
            getMaster().ProgressBarConfigure(
                "Progress Bar Test",
                "Cancel",
                "Elapsed Time",
                null, //"3estimatedTime",
                "4total",
                null, //"totalFiles",
                null, //"transferSpeed",
                true
                );
        }

        protected void btnConfigure_Click(object sender, EventArgs e)
        {
            setupProgressBar();
        }

        protected void btnBeginUpdates_Click(object sender, EventArgs e)
        {
            _curStep = 0;
            getMaster().ProgressBarReset(); // It's wise to always do a reset.

            for (int i = 0; i <= _maxStep; i++)
            {
                if (Response.IsClientConnected & !_cancelled)
                {
                    getMaster().ProgressBarUpdate(
                        null,
                        _curStep,
                        _maxStep
                        );

                    _curStep++;
                }
                else
                {
                    // If Response.IsClientConnected == false,
                    // the user clicked Cancel or closed their browser.
                    _cancelled = false;
                    getMaster().ProgressBarReset();
                    break;
                }
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            _cancelled = true;
            getMaster().ProgressBarHideNow();
            getMaster().ProgressBarReset();
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            setupProgressBar();
        }


    }
}

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 30 Jan 2012, 12:36 PM
Hi Lars,

I reviewed the provided code and it looks totally correct to me.

The controls seems to be correctly accessed in the content page and it should work in this scenario. Could you please provide the whole stack trace of the error you are facing so i can see more details on it.
Also it will be best if you could open a regular support ticket and send us runnable version of your application. Thus we will be able to debug is locally and advise you further.


Greetings,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Ajax
Asked by
Lars
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or