Page view counter

Create UpdateProgress programmatically

Rate It (1)

Last post 02-07-2008 3:38 PM by jbezanson. 5 replies.

Sort Posts:

  • Create UpdateProgress programmatically

    02-07-2008, 9:12 AM
    • Loading...
    • jbezanson
    • Joined on 10-16-2004, 1:08 AM
    • Kingston (CAN)
    • Posts 173
    • Points 735

    How can I create an UpdateProgress in the codebehind? I need to do this because I would like to wrap it in a CompositeControl.

    I tried adding the content to the Controls collection of the UpdateProgress but got an error saying it needed to have a ProgressTemplate. How can I add that? 

    Justin Bezanson

    Web Development Blog
  • Re: Create UpdateProgress programmatically

    02-07-2008, 9:33 AM

    The UpdateProgress is not accessible until very late in the page's lifecycle.  It cannot be accessed during Page_Load, _Init, _PreRender, and must be accessed before Page_Unload.  I've only found it accessible in the Page_PreRenderComplete event. 

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: Create UpdateProgress programmatically

    02-07-2008, 10:00 AM
    • Loading...
    • jbezanson
    • Joined on 10-16-2004, 1:08 AM
    • Kingston (CAN)
    • Posts 173
    • Points 735

     Thanks but I am creating the UpdateProgress completely in the CodeBehind and adding it to form1.Controls. I am not trying to access it from CodeBehind. I am creating it.

     

    1    UpdateProgress1 = new UpdateProgress();
    2 UpdateProgress1.ID = "UpdateProgress1";

    How do I add the ProgressTemplate?

    I tried this but got an error saying that the ProgressTemplate is required.

     

    1    UpdateProgress1.Controls.Add(new LiteralControl("Loading..."));
     
     
    Justin Bezanson

    Web Development Blog
  • Re: Create UpdateProgress programmatically

    02-07-2008, 1:23 PM
    Answer

    Okay, here's how you do it, but if you want an explanation why, you'll have to wait until I get around to blogging this (hopefully tonight! Smile). 

    Partial Class Default9
        Inherits System.Web.UI.Page
    
        Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
            ' !!!THIS MUST BE DONE IN THE PRERENDER EVENT!!!
            ' Create the label.
            Dim lab As New Label
            lab.ID = "Label1"
            lab.Text = "Please wait..."
    
            ' Create the UpdateProgress.
            Dim uprog As New UpdateProgress
            uprog.AssociatedUpdatePanelID = UpdatePanel1.ClientID
            uprog.ID = "UpdateProgress1"
    
            ' Create the ProgressTemplate based on a class the implements ITemplate.
            Dim value As New MyTemplate
            uprog.ProgressTemplate = value
    
            ' Add the Label to the UpdateProgress and the UpdateProgress to the form.
            uprog.Controls.Add(lab)
            Form.Controls.Add(uprog)
        End Sub
    
    End Class
    
    ' THIS GOES IN YOUR PAGES CODE BEHIND ALSO!
    Public Class MyTemplate : Implements ITemplate
    
        Public Sub InstantiateIn(ByVal container As Control) Implements Web.UI.ITemplate.InstantiateIn
            ' This is empty.
        End Sub
    
    End Class
     
    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: Create UpdateProgress programmatically

    02-07-2008, 2:09 PM
    • Loading...
    • jbezanson
    • Joined on 10-16-2004, 1:08 AM
    • Kingston (CAN)
    • Posts 173
    • Points 735

     Awesome, I'll be sure to try this and let you know right away how it works out.

    Justin Bezanson

    Web Development Blog
  • Re: Create UpdateProgress programmatically

    02-07-2008, 3:38 PM
    • Loading...
    • jbezanson
    • Joined on 10-16-2004, 1:08 AM
    • Kingston (CAN)
    • Posts 173
    • Points 735

     This works great in a WebForm. Thanks so much. I will be trying it out in a Composite Control next.


    What is your blog url? I will be waiting to read that post. Thanks again!  ***NVM I found the url in your sig.

    Justin Bezanson

    Web Development Blog
Page 1 of 1 (6 items)