i would like to know is it possible to just refresh a function in every 5 sec but without refresh the whole page?
Becoz i think it's not a good idea to keep my page refresh in every 5 sec. (waste server resources) Please advice. TQ
Below is my coding...
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
sendMT() 'my function
Label1.Text = "Last refreshed at: " & Format(CDate(Now()), "dd-MM-yyyy hh:mm:ss")
End Sub
hi, it's working fine actually.. but is refresh the whole page but not ONLY the function..
(is it possible? coz i dunwan keep refresh my page in every 5 sec, wasting my traffic bandwidth of server. and migth coz the server take it as attacking.)
You could use AJAX, an UpdatePanel and a Timer. Put the Timer and table in the UpdatePanel, and trigger a re-bind of the data with the timer.
Here is a simple example, quickly done in VS with a new AJAX webform, using code on the page rather than in code behind.
This example uses an SQLDataSource and GridView because they could be quickly added to the page, but you can, of course, populate the data any way you want. In the example, any changes to the data in the table made elsewhere show up on this page in 10 second intervals.
kengkit
Member
120 Points
246 Posts
refresh a function without refresh the whole page.
Dec 15, 2012 02:12 AM|LINK
Hi all,
i would like to know is it possible to just refresh a function in every 5 sec but without refresh the whole page?
Becoz i think it's not a good idea to keep my page refresh in every 5 sec. (waste server resources) Please advice. TQ
Below is my coding...
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick sendMT() 'my function Label1.Text = "Last refreshed at: " & Format(CDate(Now()), "dd-MM-yyyy hh:mm:ss") End Sub<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="5000"></asp:Timer> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Font-Names="Arial"></asp:Label><br /> <br /> <asp:Label ID="Label2" runat="server" Font-Names="Arial" Font-Size="Large" ForeColor="Red" Text="This page is running auto script. Please do not close it." Width="300px"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </form> </body>Kulrom
Contributor
4834 Points
893 Posts
Re: refresh a function without refresh the whole page.
Dec 15, 2012 08:21 AM|LINK
What is sendMT() ? Javascript or VB ?
Does it interact with the other controls outside of UpdatePanel?
My Blog: ASP.NET Stuff
kengkit
Member
120 Points
246 Posts
Re: refresh a function without refresh the whole page.
Dec 15, 2012 11:58 AM|LINK
Hi Kulrom,
sendMT is a function to trigger some update works. (VB)
It's not interact with other controls. TQ
Kulrom
Contributor
4834 Points
893 Posts
Re: refresh a function without refresh the whole page.
Dec 15, 2012 10:48 PM|LINK
Meaning it is certainly possible to refresh only one portion of the page using AJAX but i can't say why your code does not work as expected.
Please post the code so i can help further.
My Blog: ASP.NET Stuff
kengkit
Member
120 Points
246 Posts
Re: refresh a function without refresh the whole page.
Dec 16, 2012 01:01 AM|LINK
hi, it's working fine actually.. but is refresh the whole page but not ONLY the function..
(is it possible? coz i dunwan keep refresh my page in every 5 sec, wasting my traffic bandwidth of server. and migth coz the server take it as attacking.)
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: refresh a function without refresh the whole page.
Dec 17, 2012 02:28 AM|LINK
Here is a simple example, quickly done in VS with a new AJAX webform, using code on the page rather than in code behind.
This example uses an SQLDataSource and GridView because they could be quickly added to the page, but you can, of course, populate the data any way you want. In the example, any changes to the data in the table made elsewhere show up on this page in 10 second intervals.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Timer1_Tick(object sender, EventArgs e) { Table1.DataBind(); Notice.Text = "Table refreshed at: " + DateTime.Now.ToLongTimeString(); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function pageLoad() { } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick"> </asp:Timer> <asp:Literal ID="Notice" runat="server"></asp:Literal> <br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [TemplateName] FROM [Templates]"></asp:SqlDataSource> <asp:GridView ID="Table1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="TemplateName" HeaderText="TemplateName" SortExpression="TemplateName" /> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> </div> </form> <p>Outside the Update Panel. Not refreshed by timer.</p> </body> </html>http://aspsnippets.com/Articles/Refresh-or-Reload-part-of-page-periodically-at-regular-intervals-in-ASP.Net.aspx
http://forums.asp.net/t/1615915.aspx/1
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.