Wednesday, July 17, 2013

How to fix Master Table always NULL in get_masterTableView() method in Telerik Grid

I encounter a very weird issue today when i implemented a new feature with Telerik grid in my app

since i only manipulate the telerik grid from the client side.  the following is the snippet of my javascript code.

  var gridMasterTable = $find("<%=leadGrid.ClientID%>").get_masterTableView();
            gridMasterTable.set_dataSource(new Array());
            gridMasterTable.dataBind();

I try to bind the grid with empty array to show the grid. unfortunately the application always stop and show the warming message to indicate the master table is null.. it means that the table does not exist in the grid.

after I google the web for the solution, this post really help me identify the cause of the issue

http://www.telerik.com/community/forums/aspnet-ajax/grid/find-quot-lt-gridresults-clientid-gt-quot-get-mastertableview-is-coming-back-null.aspx

the trick to solve this issue is that when you bind your grid in the client side. you must have the onCommand property set in the ClientSettings section



 <ClientSettings>
         <ClientEvents OnGridCreated="leadGrid_Created" OnCommand="Customer_Command"/>
 </ClientSettings>

 

Thursday, July 11, 2013

How to enable Web API Session feature in Windows authentication Web Application

Recently i use javascript to call Web API method to set and load the object store in the session in IIS server.

when i try to run the application, I never was able to retrieve the object from the session, when i debug the method in the web api controller, it indicated that the session was always null.


 since the Web API had disabled the session by default, we can use the following code to force the Web API to support the session.

 protected void Application_PostAuthorizeRequest()
 {
    if (IsWebApiRequest())
    {
       HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
    }
 } 
 
private static bool IsWebApiRequest()
{
   return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith("~/api");
 }

after i put the above code in the Global.asax file, the session objects are enable.

 Now i can save the object in the session and update or retrieve from the session.