Load listview with Jquery postback

716 Views Asked by At

I am new to Jquery and want to build a listview which will be created from codebehind function. And I want a Jquery function which will do this without page postback. Actually to implement UpdatePanel functionality but without using UpdatePanel.

1

There are 1 best solutions below

1
On

use jQuery load to call a server page which returns you the Markup for the ListView/ table

//inlcude jQuery library here
<div id="myDiv"></div>
<script type="text/javascript">

    $(function(){

      //This code will execute once DOM is ready
      $("#myDiv").load("myServerPage.aspx");        

    });
</script>

And in the myServerPage.aspx, You can return the HTML Markup to be shown in the main page.

 protected void Page_Load(object sender, EventArgs e)
 {
    StringBuilder strItems = new StringBuilder();
    strItems.Append("<table>");
    //You can replace the below dummy for each loop with your code 
    //to read data from database.
    for(int i=0;i<10;i++)
    {
      strItems.Append("<tr><td>"+i.ToString()+"</td><td>I am awesome</td></tr>");    
    } 
    strItems.Append("</table>");
    Response.Write(strItems.ToString());
 }

If it is simple HTML Markup, I would use an ashx handler instead of an aspx page.

the load function will load the markup your are returning from the myServer.aspx page. It wont have the Events you usually get with the ListView server control.