Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to refresh data on website when any updation in database is done
Posted

The client browser does not know any activity happening on the server.

So you need to refresh the browser window periodically using a asp:Timer or HTML meta refresh tag.
 
Share this answer
 
Comments
sukhjeettiwana 29-Mar-12 9:14am    
i have used meta tag but it doesn't bring the change done in database i.e. when new row is inserted it doesn't show this even after manually refreshing browser window any help
Muralikrishna8811 29-Mar-12 9:38am    
Cay you specify your code for retrieving DB Data
bbirajdar 29-Mar-12 9:40am    
Ideally this should not happen. When a page refreshes, it will go through the complete page life cycle.

In this case I guess there is problem with your databind logic. You need to paste the code so that we can inspect.
sukhjeettiwana 29-Mar-12 10:00am    
Basically I am dislaying data from database row by row

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Timer1.Enabled = true;
SqlConnection con = new SqlConnection(c.con());
SqlDataAdapter adp = new SqlDataAdapter("select notice_id from notice where status like 'display' order by notice_id desc ", con);
adp.Fill(dt);
if (dt.Rows.Count != 0)
{
SqlConnection con1 = new SqlConnection(c.con());
SqlDataAdapter adp1 = new SqlDataAdapter("select * from notice where notice_id=" + Convert.ToInt32(dt.Rows[0][0]), con1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
Label1.Text = dt1.Rows[0][3].ToString();
Label2.Text = dt1.Rows[0][2].ToString();
Label3.Text = dt1.Rows[0][5].ToString();
}
else
{
Timer1.Enabled = false;
}
}
}
On timer
protected void Timer1_Tick(object sender, EventArgs e)
{
i++;
if (i < dt.Rows.Count)
{
SqlConnection con1 = new SqlConnection(c.con());
SqlDataAdapter adp1 = new SqlDataAdapter("select * from notice where notice_id=" + Convert.ToInt32(dt.Rows[i][0]), con1);
DataTable dt1 = new DataTable();
adp1.Fill(dt1);
Label1.Text = dt1.Rows[0][3].ToString();
Label2.Text = dt1.Rows[0][2].ToString();
Label3.Text = dt1.Rows[0][5].ToString();
}
else
{
i = 0;
}
sukhjeettiwana 29-Mar-12 10:30am    
ok this problem is solved but by meta tag refreshing of page can be done only after fix time but i want the refreshing only when it reaches at end of database
You can do auto refresh periodically at particular time interval by configuring meta tags.

Automatic web page refresh can be implemented in an ASP.NET (.aspx) web-page by adding some HTML code in the header section.

You can simply add following line of code in the Header section to enable auto refresh in an ASP.NET web page.

HTML
<meta http-equiv="refresh" content="120"></meta>


Where 120 refers to the number of seconds it will take before refreshing the page.
Also you can redirect to a specific page if you put the URL inside the tag.

HTML
<meta http-equiv="refresh" content="15;url=http://jinaldesai.net"></meta>


In reality, this is standard HTML functionality and nothing specific to ASP.NET. The same effect of auto-refresh would be seen whether it is an ASP.NET page or just a HTML page, or a page made in Java, PHP, ColdFusion, Perl or the like.
If you want to set the refresh time dynamically then that can be done in ASP.NET by adding server side code in the Page_Load function to set it, as shown below:

C#
Response.AppendHeader("Refresh"", "120")


Get a good example with source code here:
Auto Refresh Web Page


Hope this help!
 
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