Results 1 to 2 of 2

Thread: UpdatePanel - update twice in same routine

  1. #1

    Thread Starter
    Hyperactive Member vbcode1980's Avatar
    Join Date
    Nov 2005
    Location
    Anywhere the wind blows
    Posts
    365

    UpdatePanel - update twice in same routine

    Hi,

    I'm trying to do a number of large queries in the same routine, and have a label in an updatepanel update after each one.

    I must be doing something wrong, however, because whenever I fire up the routine, my label won't update until the last query is done.
    Isn't it possible to do UpdatePanel.Update multiple times in the same routine/event?
    This is the code I'm using:

    Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            lblStatus.Text = "Busy with task 1"
            UpdatePanel1.Update()
    
            LongTask()
    
            lblStatus.Text = "Busy doing task 2!"
            UpdatePanel1.Update()
    
            LongTask()
    
            lblStatus.Text = "Done!"
            UpdatePanel1.Update()
        End Sub
    
        Private Sub LongTask()
            conn = New SqlConnection(connstring)
            conn.Open()
            cmd = New SqlCommand("Select * from very_large_table", conn)
            cmd.CommandType = CommandType.Text
            reader = cmd.ExecuteReader()
        End Sub
    When the form loads, the lblStatus is emtpy.
    When I click the button, I see the page loading until it displays 'Done!'.
    I don't see the other texts.

    This is the page source:
    Code:
    <&#37;@ Page Language="VB" 
            MasterPageFile="~/MyApp.master" 
            AutoEventWireup="false" 
            CodeFile="test_page.aspx.vb" 
            EnableEventValidation="false"
            Inherits="test_page" 
            title="MyApp" 
            Theme="DefaultTheme" 
            %>  
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="lblStatus" runat="server"></asp:Label>
                <asp:Button ID="Button1" runat="server" Text="Update!" onclick="Button1_Click" />            
            </ContentTemplate>
        </asp:UpdatePanel>        
    </asp:Content>
    The page has a masterpage that contains the neccesary Scriptmanager.

    Can anyone tell me why it's not working?
    Last edited by vbcode1980; Feb 4th, 2011 at 08:07 AM. Reason: editing typo
    I code C#....

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: UpdatePanel - update twice in same routine

    Hello,

    In this case, what you actually need is two updatepanels.

    The first, to perform the long running action, and the second one to check on the progress. The long running task would need to write to something like a Session variable, to indicate the progress of the long running task, which the other UpdatePanel can then read.

    Although it doesn't explicitly use an UpdatePanel, there is an application example here:

    http://devarchive.net/displaying_pro...processes.aspx

    Which uses a similar approach.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width