jquery and UI templating!!

jquery could be very much helpful while performing templating i.e. rendering controls. 

I've followed the following steps for doing this.

1. on document ready function of jquery, I called its ajax behaviour.

 

 


  1. $(document).ready(function(){

  2.     $.ajax({
  3.         type:"POST",
  4.         url:"test.asmx/GetListData",
  5.         data:"{}",
  6.         contentType:"application/json; charset=utf-8",
  7.         dataType:"json",
  8.         success:function(msg){

  9.         $('#listData').removeClass('loading');
  10.         $('#listData').html(msg);
  11.     }
  12.     });

  13. });

 

 

 

2.  then, i created a usercontrol which contains datalist for templating.

on its code behind i wrote following code.

 

 

  1.          public object Data;
  2.         protected void Page_Load(object sender, EventArgs e)
  3.         {
  4.             DataList1.DataSource = Data;
  5.             DataList1.DataBind();
  6.         }

 

3. after that i created a webservice and passed the usercontrol path and data to ViewManager's Render method. This resembles with MVC which is booming in asp.net these days.

 

 

  1.  NorthWindDataset.CategoriesDataTable dt = new NorthWindDataset.CategoriesDataTable();

  2.             CategoriesTableAdapter da = new CategoriesTableAdapter();
  3.             dt = da.GetData();

  4.             if (dt.Count > 0)
  5.             {
  6.                 return ViewManager.RenderView("~/UserControls/listData.ascx", dt);
  7.             }
  8.             else
  9.             {
  10.                 return ViewManager.RenderView("~/UserControls/listData.ascx", null);
  11.             }

 

 

 

Finally, I ran my code. it worked great and superfast to asp.net ajax style. Just download the sample below and judge yourself.

 

download source code: jqajax.zip

 

Published 11-03-2008 5:01 AM by Padam Raj Gurung

Comments

# re: jquery and UI templating!!

Wednesday, December 31, 2008 12:58 PM by Risman Adnan

Hi Padam,

You can try to use SkyDrive to upload files. It will be nice because it has Windows Live Writer Plugin too.

Thanks for your contribution to MSDN NEPAL!