vyclarks
vyclarks

Reputation: 878

Auto update a table with AJAX

I'm a new to ASP.Net, and this is my first ASP project. Hope you dont mind if my problem is so simple with some people.

I'm programming a Student's Forum.

In Comment.aspx, I use Repeater Control to get all comment (for each topic) and display them order by Time desc.

<asp: Repeater....
....//
</asp: Repeater...>

But it seems this thing is not simple as I imaged. I have to not only show all comment in this topic but also update the when a comment added into Database.

I can load all comments from SQL DB in to the repeater successfully, But I dont know how to auto update when Database inserted a new row without reload all the webpage.

I'm recommended to use AJAX, I've tried to find ebooks and some documents talk about AJAX but It's so hard for me to start. I really don't know how to apply AJAX on my webpage.

Can you tell me some helpful document or some examples, or some advice?

Upvotes: 2

Views: 1536

Answers (3)

Devesh
Devesh

Reputation: 4550

You can put the repeater under the UpdatePanel and rather than refreshing after every few seconds . I will make a very light ajax method either using PageMethod or jquery (if allowed) to check if the count is changed , If only the count is change we can trigger the updatePanel refresh. http://encosia.com/easily-refresh-an-updatepanel-using-javascript/ While the page is loaded first time , get the count of records from the database and put in the hidden field . Next time make a ajax call to get the count of the rows in the database and compare it will the value saved in hidden field and if is changed fired the updatepanel update. You can put the break point in both the method and see if your update panel refresh is happening or not. In code behind handle the update panel refresh and update the repeater .

Upvotes: 1

Sunny
Sunny

Reputation: 3295

You can follow this link. By this artical you will learn also about AJAX

Refresh Grid After some interval

and

Gmail style update

Hope this will help you.For further assistance please update.

Upvotes: 1

vipulsuri
vipulsuri

Reputation: 31

I can figure that out that you are new to web application programming so it will be worth reading a few topics to get started. For ajax go through this link- http://www.w3schools.com/ajax/default.asp

There is a very good JavaScript library available that is very helpful - "jQuery"

You may go through that here - http://www.w3schools.com/jquery/jquery_intro.asp

Also you can goto jQuery website to learn more about it and how to include that in your project.

Upvotes: 0

Related Questions