Asked by:
Is that possible to delay content load when using asp.net update panel

Question
-
User1570265326 posted
Alright i will try to explain my question as much as possible.
Here an asp.net update panel full page postback
As you can see it took 215 ms to complete.
However i want new content to be updated only when total 400 ms time passed. Is this possible ? So the request will be completed however it will wait 185 ms more to display postback result.
Thank you
additional info
As you can know there is no certain time when will postback completed. However i want to set a certain threshold. For example 400 ms. So if postback get completed before 400 ms, it will wait total time 400 ms before updating update panel. If it gets completed more than 400 ms there is no problem.
There must be some javascript function etc that replaces current content of update panel once it is done. Now this is the tricky part.
Once postback started i need to start a time. After postback finished i need to check how much time passed. If it reached my threshold i should let javascript to replace inside of update panel. However if the timer is not reached the threshold yet, it should wait until timer reaches threshold then allow new content updating inside update panel.
asp.net 4.5 c#
Friday, April 11, 2014 10:34 AM
All replies
-
User-183147428 posted
Hi. Could you provide more info on the application in general? What's the purpose of the thing?
Based on what you wrote, though, it seems to me like you'll need some kind of variable (probably static) to track the time of the last postback. You'll also need to make sure your page is constantly posting back (like with js and __doPostBack) so you can check the amount of time since the last postback, since web pages are static things.
Does that help at all?
Friday, April 11, 2014 11:11 AM -
User555306248 posted
Refer this - http://mattberseth.com/blog/2007/07/delay_load_an_updatepanel.html
http://encosia.com/boost-aspnet-performance-with-deferred-content-loading/
Monday, April 14, 2014 12:41 AM -
User1570265326 posted
Hi. Could you provide more info on the application in general? What's the purpose of the thing?
Based on what you wrote, though, it seems to me like you'll need some kind of variable (probably static) to track the time of the last postback. You'll also need to make sure your page is constantly posting back (like with js and __doPostBack) so you can check the amount of time since the last postback, since web pages are static things.
Does that help at all?
batman
you can check here if you want : http://www.monstermmorpg.com/gamepage.aspx
what i want is simple. each time a player on the map moves, it does a postback. but there is no certain time when will this event completed.
However i want to make sure that it gets completed at with a threshold time. what i mean is
postback will happen. but if it ends too soon, my page will wait until that threshold then update the inside of update panel.
i can not set manual delay that would cause huge delay and that is un logical. i need to let browser do postback and get results, and after received results if it was too soon wait for a while
Monday, April 14, 2014 12:55 PM -
User465171450 posted
You could actually do this on the server-side. In the event that triggers the update panel, say a button click, you could start it with:
DateTime startTime = DateTime.Now;
That gets you the time you started at. Now after you are done processing your code do the following.
TimeSpan diff = DateTime.Now.Subtract(startTime); if(diff.Milliseconds < 400) Thread.Sleep(400 - diff.Milliseconds);
You will also need to add the following using to the top of the page:
using System.Threading;
Monday, April 14, 2014 9:23 PM -
User-183147428 posted
Did markfitzme's solution work for you, or is that what you're referring to as a manual delay?
Not sure this is what you're looking for, but another possibility could be using a timer control and making your update panel update only when you tell it to:
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="400"></asp:Timer> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional"> <ContentTemplate>
</ContentTemplate> </asp:UpdatePanel>Then in your code, track the last move made so you can make sure it's been at least 400 milliseconds. Borrowing some of markfitzme's code, maybe something like:
static DateTime lastMoveTime; // this gets updated any time a player makes a move protected void Timer1_Tick(object sender, EventArgs e) { TimeSpan timeSinceLastMove = DateTime.Now.Subtract(lastMoveTime); if (timeSinceLastMove.Milliseconds >= 400) { UpdatePanel1.Update(); } }
Of course this would mean your page is posting back every 400ms (or whatever interval). Not sure that would be okay with you.
Wednesday, April 16, 2014 4:20 PM -
User1570265326 posted
You could actually do this on the server-side. In the event that triggers the update panel, say a button click, you could start it with: DateTime startTime = DateTime.Now;
That gets you the time you started at. Now after you are done processing your code do the following.
TimeSpan diff = DateTime.Now.Subtract(startTime); if(diff.Milliseconds < 400) Thread.Sleep(400 - diff.Milliseconds);
You will also need to add the following using to the top of the page:
using System.Threading;
thank you very much however this wouldn't work
because there is also network delay
Thursday, April 17, 2014 5:23 AM -
User1570265326 posted
Did markfitzme's solution work for you, or is that what you're referring to as a manual delay? Not sure this is what you're looking for, but another possibility could be using a timer control and making your update panel update only when you tell it to: <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="400"></asp:Timer> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional"> <ContentTemplate> </ContentTemplate> </asp:UpdatePanel>
Then in your code, track the last move made so you can make sure it's been at least 400 milliseconds. Borrowing some of markfitzme's code, maybe something like:
static DateTime lastMoveTime; // this gets updated any time a player makes a move protected void Timer1_Tick(object sender, EventArgs e) { TimeSpan timeSinceLastMove = DateTime.Now.Subtract(lastMoveTime); if (timeSinceLastMove.Milliseconds >= 400) { UpdatePanel1.Update(); } }
Of course this would mean your page is posting back every 400ms (or whatever interval). Not sure that would be okay with you.
thanks a lot for answer however i need something that will work at client side
because there is also network delay. i can not handle this issue at server side
is what i am explaining too complex ?
client side does a postback and it gets completed 200 ms , so client side waits 200 ms more and then update the returned results
Thursday, April 17, 2014 5:24 AM -
User-183147428 posted
Could you make use of this, or something like it?
http://devarchive.net/client-side-timer-control-asp-net-ajax.aspx
Thursday, April 17, 2014 10:25 AM -
User1570265326 posted
Could you make use of this, or something like it?
http://devarchive.net/client-side-timer-control-asp-net-ajax.aspx
nope because it doesn't explain working mechanism of update panel
i need to delay update panel updating results after postback completed
Thursday, April 17, 2014 7:18 PM