Solved

UpdatePanel doesn't display results as expected

Posted on 2013-11-18
2
320 Views
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] + " ... ";
                upResults.Update();
                if (DeleteData(connectionObj, EMPTables[i]))
                {
                    tbResults.Text = tbResults.Text + "Completed" + Environment.NewLine;
                }
                else
                {
                    tbResults.Text = tbResults.Text + "Failed" + Environment.NewLine;
                }
                upResults.Update();
            }
            return true;
        }

Open in new window


Here is the web page code:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        
    </asp:ScriptManager>
    <h1 class="red">Sync Employee Profile Data</h1>
    <table>
        <tr>
            <td>
                <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>
                </asp:DropDownList>
            </td>
            <td>
                <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:DropDownList>
            </td>
            <td>
                <asp:Button ID="btnSync" runat="server" Text="Sync Data" onclick="btnSync_Click" />
            </td>
        </tr>
    </table>
    <hr />
    <asp:Label ID="lbMsg" runat="server"></asp:Label>
    <hr />
    <h2>Results</h2>
    <asp:UpdatePanel ID="upResults" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:TextBox ID="tbResults" runat="server" TextMode="MultiLine" ReadOnly="True" Rows="30" Width="800px"></asp:TextBox>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnSync" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

Open in new window


Any help is greatly appreciated!
0
Comment
Question by:dyarosh
2 Comments
 
LVL 30

Accepted Solution

by:
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 :)
0
 

Author Closing Comment

by:dyarosh
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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Two different visual studio versions 3 29
asp day pilot 3 18
imap mails 1 22
Deploying to Azure 3 27
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now