1

I am using div to show content from database at page load by C# "innerhtml"

divid.InnerHtml="html code generated from dtabase";

but now i want to update the content of div periodically on click of some links with corresponding data from database without reloading the page. how can i do that, please help.

  • 1
    What have you tried so far? How is this question different than http://stackoverflow.com/questions/2322977/calling-functions-from-an-asp-net-code-file-with-javascript?rq=1 and http://stackoverflow.com/questions/2356604/asp-net-javascript-ajax-call-how-to?rq=1 ? – StriplingWarrior Jun 29 '12 at 17:00
  • Have a look at this for a starter: http://www.codeproject.com/Articles/17203/Using-jQuery-for-AJAX-in-ASP-NET – Allov Jun 29 '12 at 17:01
  • I cant understand the this concept can you please elaborate the concept how I can update my div with contents from database than only I can understand codes. please help. –  Jun 29 '12 at 17:08

2 Answers2

0

First off, go here: http://www.w3schools.com/ajax/default.asp

It explains it very well. Basically ajax does a 'behind the scenes' communication with the server, once the server responds, you can update the page.

More specifically, you will need to write a JavaScript ajax function that calls a page on the server with any necessary data. That page should then return the desired data, which, you can then place as desired via javascript/jquery.

Andrew Hagner
  • 804
  • 1
  • 9
  • 18
  • I'd recommend using jQuery with this as well, because it makes working with your elements much easier. You should also assign a name/id to your div so you can access it from ajax/jquery/javascript. – Andrew Hagner Jun 29 '12 at 17:53
0

I'd add a ScriptManager to the page and enable PageMethods;

and code in:

<script>
PageMethods.GetData(function(response){

divid.InnerHtml=response;

});

</script>

//c# side:

[System.Web.Services.WebMethod]

public static String GetData()
{
  //get your db data and return it
  return databasedata;
}
Entrabiter
  • 752
  • 7
  • 13