locked
Is that possible to delay UpdatePanel update on the client side? RRS feed

  • Question

  • User1570265326 posted

    I have an old system which uses UpdatePanels of asp.net

    After the postback is completed, we know that the inside of UpdatePanel is updated

    Can i delay this update somehow on the client side ? is that possible?

    So it will be like, when the postback is started, i set a javascript datetime object on the client side

    Once the postback is completed, and the data is returned from the server, before updating the client side interface, i check how many miliseconds has passed and I delay the update of the client side until certain miliseconds has passed

    is this possible?

    asp.net 4.5 c#

    Monday, May 9, 2016 5:50 PM

All replies

  • User753101303 posted

    Hi,


    Never tried but you should be able to use https://msdn.microsoft.com/en-us/library/bb311028.aspx (maybe endRequest) which should be client side object that handles UpdatePanel http requests.


    Not sure what is the purpose? Sometimes it's best to tell what is your final goal rather than to just ask about how you think it should achieve. Generally speaking you generally try to update the page as quick as possible rather than trying to slow it down.

    Monday, May 9, 2016 6:02 PM
  • User1570265326 posted

    Hi,


    Never tried but you should be able to use https://msdn.microsoft.com/en-us/library/bb311028.aspx (maybe endRequest) which should be client side object that handles UpdatePanel http requests.


    Not sure what is the purpose? Sometimes it's best to tell what is your final goal rather than to just ask about how you think it should achieve. Generally speaking you generally try to update the page as quick as possible rather than trying to slow it down.

    hi let me clarify better

    i want each update of the page to be exactly 500 miliseconds after the ajax postback request started

    however the server delay is unknown and changes for the every location

    let say that for person 1 the server delay is 122 ms

    for person 2 the server delay is 234

    for person 3 the server delay is 444

    so i would be have to delay the page update at the client side 

    for the person 1 : 378 ms

    for the person 2 : 266 ms

    for the person 3 : 56 ms

    i have checked and i found that there is a function : 

    Sys.WebForms.PageRequestManager pageLoading Event

    so if i can somehow override the function that this function calls to update the page i can achieve

    lets assume that inside 

    Sys.WebForms.PageRequestManager pageLoading Event 

    updateTheChanges function is called

    so if i can override this updateTheChanges function and call it with a delay i can achieve what i want 

    ty

    Monday, May 9, 2016 7:17 PM
  • User1570265326 posted

    Hello again

    i really need a solution for this

    can i defer the update on the client side somehow after the postback is received?

    Sunday, May 15, 2016 10:31 AM
  • User409696431 posted

    You can hide the result on the client side.

    Use z-index and positioning and create a masking div that will hide the results area.  Set visibility to hidden.  When you click a button to get results, also kick off JavaScript that makes that masking div visible, starts a timer, and makes the masking div hidden again after the time has passed, revealing whatever has appeared in the UpdatePanel in the meantime.  Here's a trivial example, using a green background for the mask to make it obvious.  Switch it to white (same color as the rest of the page) and the mask is not obvious to the user.

    An example:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Delay test</title>
        <script type="text/javascript">
            function maskme(){
                var div = document.getElementById('Mask');
                div.style.visibility = 'visible';
                setTimeout(unmaskme, 500);
            }
            function unmaskme() {
                var div = document.getElementById('Mask');
                div.style.visibility = 'hidden';
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
    
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <br />
                <div id="Mask" style="z-index: 1000; background-color: #ffd800; ; width: 900px; height: 800px; visibility: hidden;"></div>
                    <asp:UpdatePanel ID="UpdatePanel1" style="z-index: 10; ;" runat="server">
                        <ContentTemplate>                       
                            <asp:Button ID="Button1" runat="server" Text="Fetch Data" OnClick="Button1_Click" OnClientClick="javascript:maskme();" UseSubmitBehavior="false" />
                            <br />
                            Here are the results:
                            <asp:Label ID="Label1" runat="server"></asp:Label>
                        </ContentTemplate>
                    </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
    
    Code behind fetches results on the button click:
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                Label1.Text = "I'm a result";
            }

    Tuesday, May 17, 2016 4:32 AM
  • User1570265326 posted

    KathyW ty for answer however it is not solving my problem unfortunately 

    Thursday, May 19, 2016 10:33 PM
  • User753101303 posted

    So have you tried something such as Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler). You could try to record the datetime in beginRequest and wait in pageLoading.

    I always like to understand the final goal as for example depending on why you need to do the ajax query or why you need to compensate, other approches could be used. For example for a game does it Worth or in some cases you might do a computation for example to compensate for the delay or whatever...

    Friday, May 20, 2016 8:24 AM
  • User1570265326 posted

    PatriceSc

    So have you tried something such as Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler). You could try to record the datetime in beginRequest and wait in pageLoading.

    I always like to understand the final goal as for example depending on why you need to do the ajax query or why you need to compensate, other approches could be used. For example for a game does it Worth or in some cases you might do a computation for example to compensate for the delay or whatever...

    the problem is, there is no way to delay next function in javascript without blocking the UI

    so my only option is delaying the update of the updatepanel

    I saw that some people in the past successfully overwritten these functions 

    an example : http://stackoverflow.com/questions/2359637/asp-net-webforms-w-ajax-slow-rendering

    Tuesday, June 7, 2016 4:15 PM