Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have following code for DataList and the code behind in c# it is working fine.

I am trying to figure out how to refresh the page it every 10 seconds, i was thinking of placing timer but not sure which place it should go.

Any ideas how to do it? Thanks
ASP.NET
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" CellSpacing="3"
    RepeatDirection="Horizontal"  HorizontalAlign="Left"
    DataKeyField="email" DataSourceID="SqlDataSource1" Width="900px"
    onselectedindexchanged="DataList1_SelectedIndexChanged">
    <itemtemplate>

              Skipping the code here which is working fine
                </itemtemplate>

And in c#
C#
protected void Page_Load(object sender, EventArgs e)
{
  email.Text = "" + Session["email"];
}

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

        if (!this.IsPostBack)
        {
            con.Close();
            con.Open();
            cmd = new SqlCommand("SELECT C, P FROM dr WHERE email='" + email.Text + "'", con);
           
            dr = cmd.ExecuteReader();
        
        }
}
Posted
Updated 14-Nov-11 22:04pm
v3

Why go for any complex solution when the HTML can do it for you?

Use the HTML meta refresh tag on your page

HTML
<meta http-equiv="refresh" content="600"> 


http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
 
Share this answer
 
v2
Comments
Dalek Dave 15-Nov-11 4:07am    
Bloody hell!
I was giving the exact same answer!
Sergey Alexandrovich Kryukov 15-Nov-11 4:14am    
My 5.
--SA
Try this...

XML
<meta http-equiv="refresh" content="600">
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Nov-11 4:14am    
Bloody 5. :-)_
--SA
bbirajdar 15-Nov-11 5:17am    
Yes Dalek.. We both posted the same answer within a difference of few seconds ... Cheers !!!
One the page is loaded, it's on the client so that's where you need to make the refresh happen. There's a couple of ways you can do this.

1) Page directive
http://www.codelifter.com/main/tips/tip_011.shtml[^]

2) Using the setTimeout function

http://forums.digitalpoint.com/showthread.php?t=922267[^]

Both are a bit annoying in my opinion, I don't like whole page refreshes.

You could also look into anajax call to partially update the page, refreshing only the part of the page that's displaying the data.
 
Share this answer
 
JavaScript
<script type="text/javaScript">
    function timedRefresh(timeoutPeriod) {
	 setTimeout("window.location.reload(true);",timeoutPeriod);
    }
</script>

<body onload="timedRefresh(1000);">
</script>

OR

XML
<head runat="server">
    <title> Home page</title>
    <meta http-equiv="refresh" content="10" />
</head>



Here content=seconds
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900