Skip to main content

Posts

Showing posts from 2012

pjax with MVC, and form post like pjax

Last weekend I was working on a interesting project, and came across an interesting JavaScript library called pjax. More information on pjax: https://github.com/defunkt/jquery-pjax/ http://pjax.heroku.com/ pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades, It just enhances the browsing experience. I just loved the way we could use it with MVC; Below code sample explains how we could use the same with MVC. Clientside code would look as below: Since the Form post is not handled with pjax, we can do a work around as below. Updated _ViewStart.cshtml as below: @{ if (Request.Headers["X-PJAX"] != null || Request.Headers["AJAX-FORM"]!=null) { Layout = "~/Views/Shared/_PjaxLayout.cshtml"; } else { Layout = "~/Views/Shared/_Layout.cshtml"; } } _PjaxLayout.cshtml ...

Why not to have a static const in c#

This is just a thought, that I was thinking why can't we have a constant with static in C#, and the answer is 'NO'; That we cannot have a static constant; e.g: I created a class as below: public class Constants1 { public const string Const1 = "Hello"; public const string Const2 = "World"; public static string Static1 = "Hello Static"; } When we compile the program into IL, the C# compiler does a magic in IL, that the constants converts into static literals, of course it has to, that's why we are able to access the constants as Constants1.Const1

Revealing Module Pattern in JavaScript

Revealing Module Pattern makes the code to read better and more structured way, This really useful when we had to repeat the name of the main object when we wanted to call one public method from another or access public variables. This is done by adding a return statement at the end of the function that exposes the public members. The benefits of this approach are. The Revealing Module Pattern allows the syntax of your script to be fairly consistent - it also makes it very clear at the end which of our functions and variables may be accessed publicly, something that is quite useful. In addition, we also able to reveal private functions with more specific names if we wish. The following code demonstrates how the module can be revealed. var myModule = (function () { var name = 'Mohamed Rafeeq'; var age = 28; function updatePerson() { name = 'Mohamed Rafeeq Updated'; } function setPerson() { name = 'Mohamed Rafeeq Set...

Simplified signaling with SignalR

Introduction Users are always interested in a rich experience, or a well UI Experience. They expect real-time action between both client and server, no matter if the technology used is HTML5 web sockets or something else. There comes the SignalR. It is framework built on top of ASP.NET and JavaScript library that helps to build rich interactive web applications. We can use signalR in the scenarios where require polling server after fix interval to check if server has something which client needs to update. Well, In Definition   “ SignalR   is an asynchronous signaling framework that helps maintain persistent connections between client and server”. It uses the raw technique of keeping connections open between a web client and a web server. Actually it uses an existing technique called long polling. Behind the scenes, it could very well use Web Sockets transparently. How it works Long Polling: With long-polling, the browser sends a request to the server and ...