AJAX - PROGRESS BAR is not updating

Last post 03-06-2009 11:55 AM by kulkarna@gmail.com. 5 replies.

Sort Posts:

  • AJAX - PROGRESS BAR is not updating

    11-24-2006, 12:16 PM

    I am just starting to learn AJAX.

    I would like to know why the PERCENTAGE PROGRESS BAR ( "ProgrBar" ) is NOT updated

    ( although the file is downloaded ).

     

    What’s wrong with the code ?

     

    Here is the relevant parts of the code:

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    <body>

        <form id="formA" runat="server">

        <div  id = "divId" >

         

      

            <asp:ScriptManager ID="ScriptManager1" runat="server" />

           

            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" ></asp:Timer>  

           

            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">

                   

                         <Triggers>

                        

                           <asp:AsyncPostBackTrigger ControlId="Timer1" />

                           

                         </Triggers>

                        

                         <ContentTemplate>

                         <fieldset>

                        

                         <legend>UpdatePanel content</legend>

                            <asp:Label id="PercentageLb" visible="true"  runat="server">Percentage: 0%</asp:Label>

                                <br /> <br />

                 <asp:Image  ImageUrl="~/Images/bar_bgd.jpg" visible="true" id="BarBgd"  width="204" height="24"

                      style="z-index:1;"  runat="server"/>

                            <asp:Image ImageUrl="~/Images/bar.jpg" visible="true" id="ProgrBar" width="0" height="20"

    style="z-index:2;"  runat="server"/>

                           

                            <div id="Btn" >

                            <asp:Button ID="StartBtn" runat="server" Text="Start"  OnClick="StartBtn_Click" />

                            </div>

     

                         </fieldset>

                         </ContentTemplate>

            </asp:UpdatePanel>

           

        </div>

        

        <asp:Label id="WarnLb" visible="false" style="position:absolute;left:310px; top:175px; z-index:0;"   runat="server"></asp:Label>

       </form>

    </body>

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

     

    public partial class _Default : System.Web.UI.Page

    {

        public int percent;

     

     

        protected void Page_Load(object sender, EventArgs e)

        {

        }

     

        protected void StartBtn_Click(object sender, EventArgs e)

        {

             StartDownload();

        }

     

        protected void StartDownload()

        {

       

            FileDownloader downloader = new FileDownloader();

            downloader.DownloadComplete += new EventHandler(downloader_DownloadedComplete);

            downloader.ProgressChanged += new DownloadProgressHandler(downloader_ProgressChanged);

            downloader.Download("http://www.dreamsart.pwp.blueyonder.co.uk/PICT0033.zip", @"C:\");

     

        }

     

        protected void downloader_ProgressChanged(object sender, DownloadEventArgs e)

        {

          percent = e.PercentDone;

        }

      

        protected void Timer1_Tick(object sender, EventArgs e)

        {

            ProgrBar.Width = percent * 2;

     

            PercentageLb.Text = "Percentage: " + percent + "%";

        }

     

        protected void downloader_DownloadedComplete(object sender, EventArgs e)

        {

           WarnLb.Text = "Download complete.";

        }

    }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    If you need the background and bar images you can take them here:

     

    http://www.dreamsart.pwp.blueyonder.co.uk/stratos/bar.jpg

     

    http://www.dreamsart.pwp.blueyonder.co.uk/stratos/bar_bgd.jpg

  • Re: AJAX - PROGRESS BAR is not updating

    11-25-2006, 8:49 AM
    • Contributor
      2,646 point Contributor
    • Yani Dzhurov
    • Member since 11-23-2006, 2:02 PM
    • Sofia, Bulgaria
    • Posts 516

    Hi ,

     

    the update panel triggers causes the update panel to be refreshed - the pages is reloaded or post back.

    In this case the event handler

    protected void Timer1_Tick(object sender, EventArgs e)

        {

            ProgrBar.Width = percent * 2;

     

            PercentageLb.Text = "Percentage: " + percent + "%";

        }

    is not hit.

     

    Try placing the code from the event handler into the Page_Load function.

    The page load event is fired when the update panel is refreshed.

     

    Good luck,

    Yani 

     

  • Re: AJAX - PROGRESS BAR is not updating

    11-25-2006, 3:11 PM
    Yani, it does not work either.
  • Re: AJAX - PROGRESS BAR is not updating

    11-26-2006, 9:51 AM
    Answer
    Oops... I forgot to change the settings in web.config in order to work with AJAX.  Now it is working !
  • Re: AJAX - PROGRESS BAR is not updating

    12-19-2006, 5:59 PM
    • Member
      2 point Member
    • amu
    • Member since 12-19-2006, 8:01 PM
    • Posts 2

    Hi,

    I am doing exactly the same thing you tried to do except that I have a for loop updating values to the database and a counter to keep track of the no. of records updated. In the page load I am updating the front end text box with the counter.

    The problem is the timer is being fired after the for loop is completed and updating the text box to 0. Below is the code. Can u pls tell me what the problem is. Thanks.

    protected void Page_Load(object sender, EventArgs e)

    {

    txtCount.Text = iterationCount.ToString();

    }

    public void ProcessPayment()

    {

    iterationCount = 0;

    foreach (GridViewRow row in gvExcelFile.Rows)

    {

    if ((row.RowType != DataControlRowType.EmptyDataRow) || (row.RowType != DataControlRowType.Header))

    {

     

    iterationCount++;

     

    DateTime paymentDate;

    Int64 loanID;

    loanID = Int64.Parse(row.Cells[0].Text);

    paymentDate = DateTime.Parse(row.Cells[2].Text);

    nterest = Decimal.Parse(row.Cells[4].Text.Trim());

    principal =

    Decimal.Parse(row.Cells[3].Text.Trim());

    PaymentTool.UpdatePayments(loanID, paymentDate, principal, interest);

    }

    }

    }

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">

    <Triggers>

    <asp:AsyncPostBackTrigger ControlID="Timer1" />

    </Triggers>

    <ContentTemplate>

    <asp:Label ID="txtCount" runat="server" Text="Label"></asp:Label>

    <asp:Button ID="btnProcess" runat="server" Text="Process Payment" OnClick="btnProcess_Click" />

     

    </ContentTemplate>

    </asp:UpdatePanel>

    <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2500" Enabled ="true" >

     

    </asp:Timer>
  • Re: AJAX - PROGRESS BAR is not updating

    03-06-2009, 11:55 AM

     what web.config change are you talking about. I'm running into the same issue.

    Thanks!

Page 1 of 1 (6 items)