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.


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  

Friday, May 17, 2013

How to convert only alphabet character to uppercase or lowercase in the string

Today I got a question from my teammate how can we quickly convert those alphabet characters only in a give string.

if we want to efficiently convert find those alphabet characters and  change it to Upper or Lowercase,

use the regular expression is best approach.

first we need to define the regular expression term for the match.

[a-z] reprsents that match all lower case alphabet characters

[A-Z] will be the pattern that match all upper case alphabet.

next step
we will create a delegate that will convert the alphabet to uppercase or lowercase when the match is found

delegate(Match match)
  {
       return  match.ToString().ToUpper();
  });

the following snippet of code will demo how it works

 static void Main(string[] args)
 {
   string testString="12po78er67oiiu";
  string test = System.Text.RegularExpressions.Regex.Replace(testString, @"[a-z]"delegate(Match match)
  {
       return  match.ToString().ToUpper();
  });
}

Tuesday, April 23, 2013

How to host a Nest ASP.Net applicaiton within the same source code.

I encounter an issue when i try to use the same source code to create a sub web application under

the current web application. the following picture will show the scenario that i want to acomplish






then i will receive the follow 500 Error




after i google  the web and do some research the following will solve the issue

this link will provide me great help in solving my problem

http://stackoverflow.com/questions/782252/avoid-web-config-inheritance-in-child-web-application-using-inheritinchildapplic

I must stop the nested child application inherit System.Web and System.WebServer configuration from the parent which is the source.

<location path="." inheritInChildApplications="false">
  <system.web>
   <compilation debug="true" targetFramework="4.5"/>
   <httpRuntime targetFramework="4.5"/>
   <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
    <controls>
     <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
    </controls>
   </pages>
   <httpHandlers>
    <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" validate="false"/>
   </httpHandlers>
   <httpModules>
    <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
   </httpModules>
   <!--<httpRuntime maxRequestLength="92160000" executionTimeout="112"/>-->
   <identity impersonate="false"/>
  </system.web>
 
  <system.webServer>
   <validation validateIntegratedModeConfiguration="false"/>
   <modules runAllManagedModulesForAllRequests="true">
    <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>
   </modules>
   <handlers>
    <remove name="Telerik.Web.UI.WebResource.axd" />
    <add name="Telerik.Web.UI.WebResource.axd" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" preCondition="integratedMode"/>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
   </handlers>
   <security>
    <requestFiltering>
     <requestLimits maxAllowedContentLength="943718"/>
    </requestFiltering>
   </security>
   </system.webServer>
 </location>