UpdatePanel doesn't display results as expected

Posted on 2013-11-18
Last Modified: 2013-11-19
I have a web page that is used to Sync the data between Production and Development.  There are 31 tables and some of the tables have over 10,000 records.  I have a for loop that loops through an array with the table names and then calls a function that deletes the data from the Development table.  I want to display a message in my textbox (tbResults) that is inside the UpdatePanel (upResults) each time a table is starting the delete and then finishes the delete.  The code I am using now only updates the textbox after all of the deleting is finished and control is returned to the web page.  Only the textbox is refreshed.

Here is the code that I am using.  The DeleteAllData method is called from the btnSync_Click method which is triggered when the user clicks on the Sync button on the page.

        public Boolean DeleteAllData(OracleConnection connectionObj)
            String[] EMPTables = new String[31] {"EMP_CallCenter", "EMP_Comments", "EMP_EmployeeHistory", "EMP_IDs", "EMP_EmployeeAlignment", 
                                                 "EMP_Warnings", "EMP_PhoneNumbers", "EMP_EmployeeSchedule", "EMP_EmployeeAlignment",
                                                 "EMP_Employee", "EMP_Alignment", "EMP_Validation", "EMP_HRDistributionList", 
                                                 "EMP_ViewAgentCountWeb", "EMP_WarningType", "EMP_Suffix", "EMP_IDType", "EMP_MasterSchedule", 
                                                 "EMP_Reason", "EMP_Status", "EMP_Title", "EMP_PrimarySystem", "EMP_PhoneType", 
                                                 "EMP_SubLocation", "EMP_Location", "EMP_Language", "EMP_OpenTeam", 
                                                 "EMP_Division", "EMP_Department", "EMP_Group", "EMP_Function"};

            // Don't delete data from Production Server
            if (connectionObj.HostName == "phpdbo04")
                return false;

            // Delete data from all tables
            for (int i = 0; i < EMPTables.Length; i++)
                tbResults.Text = tbResults.Text + "Deleting data from " + EMPTables[i] + " ... ";
                if (DeleteData(connectionObj, EMPTables[i]))
                    tbResults.Text = tbResults.Text + "Completed" + Environment.NewLine;
                    tbResults.Text = tbResults.Text + "Failed" + Environment.NewLine;
            return true;

Open in new window

Here is the web page code:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <h1 class="red">Sync Employee Profile Data</h1>
                <b>Choose Source:</b> <asp:DropDownList ID="ddlSource" runat="server">
                    <asp:ListItem Value="PROD" Selected="True">PROD</asp:ListItem>
                    <asp:ListItem Value="DEV">DEV</asp:ListItem>
                    <asp:ListItem Value="UAT">UAT</asp:ListItem>
                <b>Choose Destination:</b> <asp:DropDownList ID="ddlDestination" runat="server">
                    <asp:ListItem Value="DEV" Selected="True">DEV</asp:ListItem>
                    <asp:ListItem Value="UAT">UAT</asp:ListItem>
                <asp:Button ID="btnSync" runat="server" Text="Sync Data" onclick="btnSync_Click" />
    <hr />
    <asp:Label ID="lbMsg" runat="server"></asp:Label>
    <hr />
    <asp:UpdatePanel ID="upResults" runat="server" UpdateMode="Conditional">
            <asp:TextBox ID="tbResults" runat="server" TextMode="MultiLine" ReadOnly="True" Rows="30" Width="800px"></asp:TextBox>
            <asp:AsyncPostBackTrigger ControlID="btnSync" EventName="Click" />

Open in new window

Any help is greatly appreciated!
Question by:dyarosh
LVL 30

Accepted Solution

Alexandre Simões earned 500 total points
ID: 39658699
You have a misconception there.

Although it's true that UpdatePanels let you refresh their content without refreshing the whole page, they actually behave lets say, normally like a page.
I mean, when you invoke a server side action, like your DeleteAllData, the UpdatePanel will only refresh when the whole method is finished. There's no active synchronization magic going on between the server and the client.

So to do what you want you have 4 options:
1. Stay as is, and display a simple "Processing" message that will disappear at the end. No extra interactivity.

2. Do one request per table. So basically this will require you to:
- use javascript instead of the update panel
- have the list of tables in the client side and loop through them calling a SyncTable method that would receive the table name as parameter.
- on each request call you can update the message saying "Table A sync in progress..."

3. You can simply do some sort of "Ping" function that requests the server what's the status of the process every x seconds. This also has to be done in javascript with a setTimeout, pretty easy to do. The problem here is that on the server-side you need to store the progress of the sync process in the database and you need to be careful about multiple concurrent sync requests (which in your case you should really be careful with).

4. You can get fancy and use SignalR that is in fact the tool that lets you do what you're expecting from the update panel. SignalR manages real-time connection between client and server. New browsers support Web  Sockets that are real open connections between the two but older browsers require other techniques. SignalR abstracts you from all this multi-browser support applying the best technique based on the browser.

If you want my opinion, this really depends on the amount of time this process takes.
This looks like a simple maintenance task which would be perfectly done with a simple spinning "work in progress" kind of gif in the middle of the screen.

If it really takes too much time you might run into time-out problems. In this case make it asynchronous. Have a background task to do the job and notify the user (by email for instance) when it's done.

Everything else will take you more time to fine tune than the actual sync process :)

Author Closing Comment

ID: 39659329
Thank you for the explanation.  That is what I thought was happening but needed confirmation.  The process does take longer than a simple processing so I am going to take your advice and break it up into separate calls.  Thanks.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question