?
Solved

UpdatePanel doesn't display results as expected

Posted on 2013-11-18
2
Medium Priority
?
347 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 2000 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

Independent Software Vendors: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 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