Vulnerable Cookies

I’ve Found a Great PDF about XSS Attack , and how the Middle Layer man can hijack your session and cookies. and also how to encounter it

https://www.isecpartners.com/files/web-session-management.pdf

You should always set your Domain, HttpOnly Attribute(not writeable from js) on your Cookies and use the HTTPS so the middle layer man can’t see it in plain text.

Share this post: | | | |
Posted by cipto with no comments

Merge JS into 1 Large File

Yet i come across this scenario again. After Merging all my js into 1, i found out it can’t run. this usually happens when the whole js is merge into 1 , Because Browser Lack Capability in  handling the errors when in one large file compare to one by one.

After looking 1 by 1. and using jslint. i found that Facebox.js again is not properly written. there are lot of no semicolon in the end. after adding semi colon in many lines, it runs. After that i use the JSMin to minimize it.

But what about the Server Control? Server control usually use the scriptResource.Axd .it’s a handler for the Java script for the control.

If you include many Ajaxtoolkit control,3rd Party Control which integrate with ASP.NET Ajax ex:telerik,etc.

You can see that each of that control is adding a seperate call of Scriptresource.axd.

How can we merge it?

Well first download the Helper which can detect our Asp.net ajax related Javascript References. ScriptReferenceProfiler

add to your bin. Reference on your toolbox. Put that on your page.

When you run your page, the dll will output all the Reference needed for your page .

For example:

15 References Found:

   1:  <asp:ScriptReference name="MicrosoftAjax.js"/>
   2:      <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
   3:      <asp:ScriptReference name="Telerik.Web.UI.Common.Core.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   4:      <asp:ScriptReference name="Telerik.Web.UI.Common.jQuery.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   5:      <asp:ScriptReference name="Telerik.Web.UI.Common.jQueryPlugins.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   6:      <asp:ScriptReference name="Telerik.Web.UI.Common.Navigation.NavigationScripts.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   7:      <asp:ScriptReference name="Telerik.Web.UI.ComboBox.RadComboBoxScripts.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   8:      <asp:ScriptReference name="Telerik.Web.UI.Ajax.Ajax.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   9:      <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  10:      <asp:ScriptReference name="AjaxControlToolkit.Compat.Timer.Timer.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  11:      <asp:ScriptReference name="AjaxControlToolkit.Animation.Animations.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  12:      <asp:ScriptReference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  13:      <asp:ScriptReference name="AjaxControlToolkit.AlwaysVisibleControl.AlwaysVisibleControlBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  14:      <asp:ScriptReference name="AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  15:      <asp:ScriptReference name="AjaxControlToolkit.DropShadow.DropShadowBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>

Then on Your Script Manager add all that references Under CompositeScripts->scripts Tag

   1:  <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
   2:  <CompositeScript ScriptMode="Release">
   3:  <Scripts>
   4:  <asp:ScriptReference name="MicrosoftAjax.js"/>
   5:      <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
   6:      <asp:ScriptReference name="Telerik.Web.UI.Common.Core.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   7:      <asp:ScriptReference name="Telerik.Web.UI.Common.jQuery.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   8:      <asp:ScriptReference name="Telerik.Web.UI.Common.jQueryPlugins.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
   9:      <asp:ScriptReference name="Telerik.Web.UI.Common.Navigation.NavigationScripts.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
  10:      <asp:ScriptReference name="Telerik.Web.UI.ComboBox.RadComboBoxScripts.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
  11:      <asp:ScriptReference name="Telerik.Web.UI.Ajax.Ajax.js" assembly="Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>
  12:      <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  13:      <asp:ScriptReference name="AjaxControlToolkit.Compat.Timer.Timer.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  14:      <asp:ScriptReference name="AjaxControlToolkit.Animation.Animations.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
  15:  </Scripts>
  16:  </CompositeScript>
  17:  </asp:ScriptManager>

If You reference Too many Script Reference it will throws Error . like “too many script references , can’t exceed 1024 Characters”

Well You have to split it on another one using The scriptmanagerProxy. you can also you scriptmanager proxy on your Sub COntrol(Ascx)

Actually What you will have now is 2 ScriptResource.axd. So each scriptmanagerproxy will result in new ScriptResource.axd Group

For Example:

   1:  <asp:ScriptManagerProxy runat="server">
   2:  <CompositeScript ScriptMode="Release">
   3:  <Scripts>
   4:      <asp:ScriptReference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
   5:      <asp:ScriptReference name="AjaxControlToolkit.AlwaysVisibleControl.AlwaysVisibleControlBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
   6:      <asp:ScriptReference name="AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
   7:      <asp:ScriptReference name="AjaxControlToolkit.DropShadow.DropShadowBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30512.17815, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
   8:   
   9:  </Scripts>
  10:  </CompositeScript>
  11:  </asp:ScriptManagerProxy>

The Less HttpRequest there are, the faster the Page will load,Especially JS.

Because Browser Behavior Tend to  Block Other Downloads Until the JS is finished Downloaded

And As usual you should put the JS before the Body End Tag

 

Share this post: | | | |
Posted by cipto with no comments

Usage of FLVTOOL

You can download flvtool from official website

FLVTool set meta information that is used by flash player to properly stream flv videos.

If FLVTool proper set meta information, then original flv file size increase about 1kb.

It is useful when you implement partial streaming like youtube does.

In partial streaming user can stream video from any location. from start, middle or end of video.

Also if meta information not set for flv videos most of desktop flash players like http://download.cnet.com/FLV-Player/3000-2139_4-10505954.html showing Shows bitrate as 0kb/s.

Share this post: | | | |
Posted by cipto with no comments

My Summary of Composite WPF&Silverlight, a.k.a Prism

After finding Quite a number of screen cast, It's quite hard to understand at first. the starting Comprehensive Video that i found are the Videos from the silverlightBayLabs,it's very nice and simple Anyway for Our application which use many controls in 1 xaml and have many interaction with each other it is a Very nice If Our Silverlight App can be Tested And Become Modular

This can be done by composite Application Block. Similar To other Type of application ,Composite Block for web it's WCSF and SCSF for the Windows Form.

What it does is almost the same. Shell is the end point. shell does not know anything. It only job is to Register Which Modules for this application We than separate our concern into separate module , seperate project. On Module which inherit from IModule , which has 1 method ->Initialize We register our Type And View and region .As for other Type of Work/Behaviour we add on this Module project. After A couple of this screen cast i finally grasp the idea. Especially MVVM

Shell.Xaml is our master page we register our View Using RegionManager. We seperate our View From it's Logic and Event. Model - ViewModel. ViewModel will consist of our logic , it's an island of it self. he does not know about the view at all. We can seperate /loosely coupled this Class Using depedency Injection. You just called the IUnityContainer. UnityContainer is like a Holder for your type. and it can initiate what Type you need.

EventAggregator work for use to publish event to subscriber. it acts like a mediator for you.So your Cross module can just register to it.

DelegateCommand is the One who can pass the Click Event from the Xaml to View Model. default is click only but can be extended.

To Make a Silverlight app Test project just reference 2 dll: Microsoft.Silverlight.testing ,Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight

To Make Blend Work And can Search for our Behaviour reference 1 dll on the project: Microsoft.Expression.Interactiviy

The Composite Block use weak reference on binding. we have to make our eventhandler method Public so that can be Unsubscribe from the event All the bold ones are the helper for us to use to implement MVVM/MVP

07/02/2010

There are discussion over MVVM , that it is lack of template , OverHead when used on Large application.it lack of pattern like wheter we put this on view model or the behind code view it self

http://en.wikipedia.org/wiki/MVVM

Share this post: | | | |
Posted by cipto with no comments

Facebox Stays Under Flash

No matter what you do.. set the zindex.. it won't change the Flash is always on top of facebox. if you set wmmode=transparent on somecases , you can't see the flash. Solution add param to your Flash wmmode = block
Share this post: | | | |
Posted by cipto with no comments

Child Calling Parent Method/ Iframe Reload from child

This is the example, when a child wanna call it's parent.

including A child page of iframe wanna Adjust the IFrame parent Height and width

The trick is simple access your iframe method from parent.yourmethod();

depends on the hierarcy it can be parent.parent.n...

Example:

Child:

function ChildResizeIframe(height) { 
 
try { 
 
parent.parent.ParentResizeIframe(height); 
 
} catch (e) {
 
 }
 
 } 
 
window.onload = function() 
 
{ 
 
ChildResizeIframe(450); 
 
}; 

Parent:

function ParentResizeIframe(height) { 
//do something with iframe, or other element 
}

Share this post: | | | |
Posted by cipto with no comments

Detecting Mobile Device and Search Engine Crawler Bots

   1:   //Check if Google Bot/Crawler
   2:          //or IS a Crawler 
   3:          //Give full version web
   4:          System.Web.HttpBrowserCapabilities myBrowserCaps = Request.Browser;
   5:          bool crawler =myBrowserCaps.Crawler;
   6:          
   7:          if(Request.Browser.IsMobileDevice && !crawler)
   8:          Response.Redirect("MyMobile.aspx");

Note myBrowserCaps.Crawler

Works againts Google Bots 2.1,MSN Bot 1.1.

But not working for Yahoo Slurp.

The idea is if A crawler on our site, we give them full site  so that Goggle/Other search engine does not put our web application as mobile application

Share this post: | | | |
Posted by cipto with 1 comment(s)

GridView Paging with ObjectDataSource

Ok I wanna Blog about this.

I read on MSDN, Among the other Datasource, Like sql datasource , etc.

The only Data Source that can call by Page is Object Data Source. So it will not Take All Rows First Than do a Paging. Which is not efficient.

In order The Object Data Source to work with your Grid Request.

You need To : EnablePaging = True. If false it will Not Passed the startrowindex and MaximumRowsParameter.

Supply At Least

  • StartRowIndexName if the name is different than ‘startrowindex
  • MaximumRowsParameter if it’s different than default.
  • TypeName , Your class Type with Namespace if necessary. it is where object data source will look for your select method, and all other operation method stuff
  • SelectCountMethod, the method name in your TypeName that is used for counting total rows of the query
  • SelectMethod, The method That is used for selecting rows. Here is where the startrowindex and maximumrowsparameter WIll Goes to.
  • SortParameterName, If you want to support sorting , This is The name of param on selectMethod .object datasource will passed the gridview SortExpression property automatically

On your GridView, set the PageSize, this will effect the maximumrowsparameter

Example of SelectMethod

   1:   
   2:          /// <summary>
   3:          /// This returns a list of students based on paging.
   4:          /// </summary>
   5:          /// <param name="sortExpression">SortExpression,CustomFormat:[columname][asc/desc]</param>
   6:          /// <param name="startRowIndex">The starting Row from object data Source</param>
   7:          /// <param name="pageSize">The Size of Row, 5 in this case</param>
   8:          /// <returns></returns>
   9:          [DataObjectMethod(DataObjectMethodType.Select)]
  10:          public static List<Student> GetStudents(string sortExpression, int startRowIndex, int pageSize)
  11:          {
  12:              if (String.IsNullOrEmpty(sortBLOCKED EXPRESSION sortExpression = "IDDesc";
  13:              startRowIndex++;
  14:              int pagenumber = startRowIndex/pageSize;
  15:              pagenumber++;
  16:              var students = new List<Student>();
  17:              var parameters = new SqlParameter[4];
  18:              var param = new SqlParameter("PageNumber", SqlDbType.Int);
  19:              param.Value = pagenumber;
  20:              parameters[0] = param;
  21:   
  22:              param = new SqlParameter("PageSize", SqlDbType.Int);
  23:              param.Value = pageSize;
  24:              parameters[1] = param;
  25:   
  26:              var howManyRowsReturnedParam = new SqlParameter("@HowManyRows", SqlDbType.Int);
  27:              howManyRowsReturnedParam.Direction = ParameterDirection.Output;
  28:              howManyRowsReturnedParam.Value = "";
  29:              parameters[2] = howManyRowsReturnedParam;
  30:   
  31:              param = new SqlParameter("orderby", SqlDbType.VarChar);
  32:              param.Value = sortExpression;
  33:              parameters[3] = param;
  34:   
  35:   
  36:              using (
  37:                  SqlDataReader dr = SqlHelper.ExecuteReader(Connections.Conn1, "GetStudent", CommandType.StoredProcedure,
  38:                                                             parameters))
  39:              {
  40:                  while (dr.Read())
  41:                  {
  42:                      var s = new Student();
  43:                      s.ID = int.Parse(dr["ID"].ToString());
  44:                      s.Name = dr["Name"].ToString();
  45:                      s.City = dr["City"].ToString();
  46:                      s.State = dr["State"].ToString();
  47:                      s.Phone = dr["Phone"].ToString();
  48:                      s.Email = dr["Email"].ToString();
  49:                      s.CreatedOn = DateTime.Parse(dr["CreatedOn"].ToString());
  50:   
  51:                      students.Add(s);
  52:                  }
  53:              }
  54:              return students;
  55:          }
  56:      }

There are also Trick on your Store procedure for Dynamic Sorting, Like this:

   1:  ROW_NUMBER( ) over (order BY 
   2:              case 
   3:              when @orderby='IDAsc' then [ID] END ASC,
   4:              case 
   5:              when @orderby='IDDesc' then ID END DESC,
   6:              case 
   7:              when @orderby='NameAsc' then [NAME] END ASC,
   8:              case 
   9:              when @orderby='NameDesc' then [NAME] END DESC,
  10:              case
  11:              when @orderby='CityAsc' then City END ASC,

So in order to make this custom Ascending / Descending work i need to put the custom sorting expression on variable

 protected void gvStudent_sorting(object sender, GridViewSortEventArgs e)
        {
            string sortDirection = e.SortDirection == SortDirection.Descending ? "Desc" : "Asc";
            SortBy = e.SortExpression + sortDirection;
        }

Now this is also important,  The Object Data Source will Call your Select Method Twice because of it’s own Cache Logic internal. so the first one will be like always requesting for first page. and the second call will be the correct StartRowindex. So it is used for Object Data Source Internal Checking. there’s nothing wrong with it

The object Data Source have a important Method Like Selecting. ODS will called this selecting twice , 1st call Is To Fetch Data, 2nd Is for Gettting The Total Count Method(return integer)

I passed in my Custom Sorting Expression Variable Value Here.

   1:    private void StudentDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
   2:          {
   3:              //fecthdata
   4:              if (!e.ExecutingSelectCount)
   5:              {
   6:                  //make custom expression param
   7:                  if (SortBy.Length > 0)
   8:                  {
   9:                      e.Arguments.SortExpression = SortBy;
  10:                  }
  11:              }
  12:          }

Share this post: | | | |
Posted by cipto with no comments

Object Reference Not Set After Copying Mobile.browser

Why am I getting "Object reference not set to an instance of an object."?
If after copying the .browser file into your AppBrowsers folder you get a compile error “Object reference not set to an instance of an object.” and you have .NET 3.5 SP1, then the issue is likely that you must create a sub-directory (of any name) in your AppBrowsers folder and place the .browser file in there. E.G. \App_Browsers\MobileBrowserData\mobile.browser

Share this post: | | | |
Posted by cipto with no comments

Service Application Unavailable IIS7

There are many things that cause this. read here For more detail and accurate step.a

Check Security, already There.

See the Log of IIS on C:\inetpub\logs\LogFiles\W3SVC1, the request return http error code 500. Not much Help

Do a ‘appcmd list appppools’

5

Nothing wrong on the application pool. No Crash

See the Event Viewer –> Application.

There’s a Information:

A request mapped to aspnet_isapi.dll was made within an application pool running in Integrated .NET mode.  Aspnet_isapi.dll can only be used when running in Classic .NET mode.  Please either specify preCondition="ISAPImode" on the handler mapping to make it run only in application pools running in Classic .NET mode, or move the application to another

Aha, my application still calling the old Way Isapi.

Change the ApplicationPool Mode to Classic

Bingo!

Share this post: | | | |
Posted by cipto with no comments

TSQL How To Synchronize Between 2 Tables

This query work to find out any difference between 2 tables and return Only The Difference Row, Or Not There Row.

if the union all Group Count return 2 meaning it’s the same ,if 1 Than there’s difference. You can put on temporary table

SELECT MIN(tableName),Column1,Column2 .. N
    FROM
    (
    --sync 
    SELECT 'Table 1' AS tableName,Column1,Column2 .. N
    FROM
    Table1
    
    UNION ALL
    SELECT 'Table 2' AS tableName,Column1,Column2 .. N
    FROM
    Table2
 
    )
    tmp
    GROUP BY Column1,Column2 ..N
    --1 means have difference, 2 means identical
    HAVING COUNT(*)=1
    ORDER BY Column1,Column2 ..N

After That , Do your Insert Update Delete Logic From The Results.

Share this post: | | | |
Posted by cipto with 2 comment(s)

System.InvalidCastException: [A]System.Collections.Generic.List`1[VideoDistribution+mediaData] cannot be cast to [B]System.Collections.Generic.List`1[VideoDistribution+mediaData]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKe

 

i’ve got this strange error on my handler. if i set isreuseable to false The error getting obvious. Like they are on differen process and different type. So finally found out that i make a protected class on my handler. Move The class to the APP_Code and that should solve this

Share this post: | | | |
Posted by cipto with no comments

.Net support for XSLT 2.0

On my way of searching Simple URL ENcode on xslt. there are few solution which i haven’t test, using encoding, Calling a built in template.

It turns out that there’s a built in function in xslt 2.0 : encode-for-uri.

And .Net support under that msscript namespace is Still 1.0.

On MSDN , when .net 2.0 released it support 1.0 because simply 2.0 is not ready yet.

There are library for this which is build by Microsoft MVP, called MVP.XML

Share this post: | | | |
Posted by cipto with no comments

XSLT Support for Calling .Net Function

.Net Support only xslt 1.0

I’ve just found out that We can call .net function inside XSLT, Example.

using msxsl:script tag

You can Make a C# function and use on your template

ain’t it cool? But read more that It’s Evil and Here:

“The problem is that when XSLT stylesheet is loaded in .NET, msxsl:script is compiled into an assembly via CodeDOM and then loaded into memory, into the current application domain. Each time the stylesheet is loaded above process is repeated - new assembly is being generated and loaded into the application domain. But it's impossible to unload an assembly from application domain in .NET!”

Share this post: | | | |
Posted by cipto with no comments

Client Side Repeater and Paging

Aloha.. So on this Article lest discuss How to Do a Repeater From Template But Client Side and Paging We are going to Use JTemplate and jquery Pagination. Imagine that a repeater that does not use server memory and Adding something to The Control Tree. :) Feed Them Json and They shall work, Neat.. So First We need a div container for Paging and the content it self, News-Pagination Div would be the paging container, and Mycontainer is End result container for our data

   1:  <div>
   2:      <div style="width:100%;">
   3:      <div id="News-Pagination" style="float:right" class="pagination"></div>
   4:      </div>
   5:      <div style="clear:both;margin-bottom:10px"></div>
   6:      
   7:      <div class="front64" id="MyContainer"></div>
   8:  </div>

On first Call we need to Set the Total Row That return (line 17), so that the paging can runs. What i don’t like about this is we have to make a double call.

We Can set The Template By URL or Feed String directly , The pattern is like line 27-28. On Next or Prev The Event Handler is Line 39

   1:  function MyInitialClass{
   2:  this.pagenumber=1,
   3:  this.pagesize=4,
   4:  this.totalmessage=0
   5:  }
   6:  var popMessage = new MyInitialClass();
   7:   
   8:  $(document).ready(function() {
   9:     FirstCall(popMessage.pagenumber, popMessage.pagesize);  
  10:   
  11:  });
  12:   
  13:  function FirstCall(pageindex, pagesize) {
  14:   
  15:      $.getJSON('services/MyHandler.ashx?p=' + pageindex + '&s=' + pagesize, function(messages) {
  16:          popMessage.totalmessage = messages.totalmessage;
  17:          $("#News-Pagination").pagination(popMessage.totalmessage, {
  18:              items_per_page: popMessage.pagesize,
  19:              callback: handlePaginationClick        
  20:          });
  21:   
  22:      });
  23:  function GetNext(pageindex, pagesize) {
  24:      $('#MyContainer').fadeOut('medium');
  25:      $.getJSON('services/MyHandler.ashx?p=' + pageindex + '&s=' + pagesize, function(messages) {
  26:          //Set and Apply template
  27:          var template = $('#item_template').html();
  28:          $('#MyContainer').setTemplate(template);
  29:          $('#MyContainer').processTemplate(messages);
  30:          //set total
  31:          for (var a = 0; a < messages.messages.length; a++) {
  32:              document.getElementById(messages.messagesAngel.rootmessageid).innerHTML = messages.messageAngel.message;
  33:          }
  34:          $('#MyContainer').hide().fadeIn('slow');
  35:         popMessage.totalmessage = messages.totalmessage;
  36:      });
  37:   
  38:  }
  39:  function handlePaginationClick(new_pageindex, pagination_container) {
  40:      GetNext(new_pageindex + 1, popMessage.pagesize);            
  41:       return false;
  42:      }
  43:   
  44:   
  45:  }

Another Trick would Be, if you see on Line 27. We are Getting Template From a Script Type=text/html.

If you put script type=text/html ,this will hide any markup in the document without interfering with HTML validator.we can put inline our Template in the Same page with out any Error and it will not displayed on page.

So Put our template on page. Below is only Example

   1:  <script type="text/html" id="item_template">    
   2:  <div>
   3:      <ul>   
   4:          {#foreach $T.messages as record}
   5:          <li>
   6:              <div class="vcard">
   7:                  <strong><a href="{$T.record.fullname}/{$T.record.shortname}" title="{$T.record.firstname} {$T.record.lastname}">
   8:                      <span class="userImage">
   9:                          <img class="photo" alt="alt tag here" src="services/imageHandler.ashx?image=images/upload/photos/c{$T.record.clientid}avbig.jpg&amp;w=63&amp;h=63&amp;always=true&amp;aspec=true&amp;nopic=noavatarl&amp;resizeby=w"
  10:                              height="63" width="63"></span><span class="nickname">{$T.record.firstname} {$T.record.lastname}</span></a></strong>&nbsp;wrote:<br>
  11:                 
  12:                  <div id="{$T.record.rootmessageid}" class="hr3"></div>
  13:              </div>
  14:          </li>
  15:         
  16:          {#/for}
  17:      </ul>
  18:  </div>
  19:  </script>
 
 
On Your Handler Do A Paging On Your Store Proc,Receving P as page and S as size and Output The endresult with Json, I use Newtonsoft.Json.Linq.JObject for a long time.
 
   1:   var json = JObject.FromObject(new
   2:                                                    {
   3:                                                        messages = (from c in result
   4:                                                                    select
   5:                                                                        new
   6:                                                                            {
   7:                                                                                fullname = c.fullname,
   8:                                                                                firstname = c.firstname,
   9:                                                                                lastname = c.lastname,
  10:                                                                                clientid = c.clientid,
  11:                                                                                shortname = c.shortname,
  12:                                                                                message = c.message,
  13:                                                                                messagetypeid = c.messagetypeid,
  14:                                                                                rootmessageid = c.rootmessageid,
  15:                                                                                sum = c.sum
  16:                                                                            }),
  17:                                                        totalmessage = howmanyitems
  18:                                                    });
  19:                  context.Response.Write(json.ToString());
  20:                  context.Response.End();

That’s it . See you again Folks

Share this post: | | | |
Posted by cipto with no comments
More Posts Next page »