Solved

UpdatePanel doesn't display results as expected

Posted on 2013-11-18
2
315 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

16 Experts available now in Live!

Get 1:1 Help Now