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.
- $(document).ready(function(){
- $.ajax({
- type:"POST",
- url:"test.asmx/GetListData",
- data:"{}",
- contentType:"application/json; charset=utf-8",
- dataType:"json",
- success:function(msg){
- $('#listData').removeClass('loading');
- $('#listData').html(msg);
- }
- });
- });
2. then, i created a usercontrol which contains datalist for templating.
on its code behind i wrote following code.
- public object Data;
- protected void Page_Load(object sender, EventArgs e)
- {
- DataList1.DataSource = Data;
- DataList1.DataBind();
- }
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.
- NorthWindDataset.CategoriesDataTable dt = new NorthWindDataset.CategoriesDataTable();
- CategoriesTableAdapter da = new CategoriesTableAdapter();
- dt = da.GetData();
- if (dt.Count > 0)
- {
- return ViewManager.RenderView("~/UserControls/listData.ascx", dt);
- }
- else
- {
- return ViewManager.RenderView("~/UserControls/listData.ascx", null);
- }
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