Reputation: 6216
So I'm using ASP.NET with C#. And I have an item that is queried from the database and displays items correctly.
I made a comment table, where user enters a piece of text, and presses an AJAX-enhanced button, to insert the comment into the database, which the table listview below displays.
However, when the user enters a comment, the table stays the same, it doesn't refresh. If I press Post a comment again, then it will display the previous comment, but not the current one.
I tried on the "post a comment" button to add the following:
CommentsView.DataBind();
No luck, it won't refresh. And some smart programmer at microsoft forgot to add a simple "ListView.Refresh()" function to ListView class.
I don't understand why AJAX doesn't automatically update the table to update the information. How do you get it to display the latest data?
Upvotes: 2
Views: 6698
Reputation: 70538
Those smart programmers at microsoft understand how databind works on apsx pages.
This involves understanding the page lifecycycle. If you read this documentation and understand it, the problem you are having should become clear.
But the quick answer is this: Right now you bind to the data in the page init. If you want that data to change you must rebind to the datasource. .NET automagically caches it for you in the viewstate otherwise.
Add some code to your "Post a comment" to rebind the datasource (and thus change the viewstate) and you should be fine.
Upvotes: 3