Monthly Archives: March 2013

jQuery Explained

How to use jQuery selectors with examples.
http://jquerybyexample.blogspot.com/2011/05/jquery-selectors-examples.html

Difference between $(this) & this in jQuery?
http://jquerybyexample.blogspot.com/2010/08/difference-between-this-and-this-in.html

Does jQuery returns error if DOM element doesn’t exist?
http://jquerybyexample.blogspot.com/2010/08/how-to-check-element-exists-or-not-in.html

What is .bind() method do? And differ from .click() ?
http://jquerybyexample.blogspot.com/2010/06/jquery-bind-function-exampledemo.html

Differ between .bind(), .live() & .delegate()?
http://jquerybyexample.blogspot.com/2010/08/bind-vs-live-vs-delegate-function.html

Understand $.proxy() in jQuery.
http://stackoverflow.com/questions/4986329/understanding-proxy-in-jquery

Leave a comment

Filed under jQuery

MVC Life Cycle Explained

1) An application has one and only one Route Table. This Route Table is setup in the Global.asax file
Initially Application_Start() event is called for the application, where we set all the Routes in the static RouteTable.Route collection (which is of type RouteCollection)

routes.MapRoute(
 "Default", // Route name
 "{controller}/{action}/{id}", // URL with parameters
 new { controller = "Home", action = "Index", id = UrlParameter.Optional }
 );

All route object map route Url to MVCRouteHandler which implement IHttpHandler.

2) The UrlRoutingModule class matches an HTTP request to a route in an ASP.NET MVC application.
UrlRoutingModule passes HttpContext object to RouteTable. The HttpContext object includes Url, form parameters, query string, cookies with the current request.

ControlFlow of MVC

3) The MapRoute method being invoked inside of the RegisterRoutes method is an extension method. Every route registered with MapRoute is configured to use MvcRouteHandler, which is a RouteHandler provided by MVC framework.
It is route handler job to find the HTTP Handler (which implement IHttpHandler) for a request, in MVC this handler is called MvcHandler.

4) When control reaches this MvcHandler, it extract the controller parameter from RouteData and send them to ControllerFactory. It is the factory responsibility to return a controller. All controller in MVC implement IController.
MVC framework provide a default controller factory named DefaultControllerFactory that will search assemblies in appdomain to the Controller with implement IController & ends with Controller. Then the same instance is returned to the MvcHandler. When MvcHandler has a IController reference, it invokes the Execute() on controller.

5) The Execute() method extract members from the Request object and some of which act as method parameter.
The Execute() method finds method of the controller by using reflection on Controller class. It finds the method (action) which matches the route and executes it.

6) When controller transfer to RenderView() method, the call is delegated to ViewEngine’s RenderView() method. It uses ViewLocator class to find the View. And all master page, ViewBag, ViewData are set.

References :
http://msdn.microsoft.com/en-us/magazine/dd695917.aspx

image

2 Comments

Filed under C#

Referential Integrity

Referential Integrity is a database concept which ensures that relationship between tables remain constant.

When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table.
There are 3 rules:
1) Insert
2) Cascading delete
3) Cascading update

Reference
http://www.programmerinterview.com/index.php/database-sql/what-is-referential-integrity/

Leave a comment

Filed under SQL

Can foreign Key be NULL and Duplicate?

Yes, Foreign Key can be NULL as well as Duplicate (duplicate in one to many relationship).

Justification
http://stackoverflow.com/questions/7573590/can-foreign-key-null-and-duplicate

Leave a comment

Filed under SQL

Reverse String

Below is the code in two approach:


class ReverseString
    {
        public string Reverse(string str)
        {
            char[] chr = str.ToArray();
            StringBuilder news = new StringBuilder();

            for (int i = str.Length - 1; i >= 0; i--)
                news.Append(str[i]);

            return news.ToString();
        }

        public string ReverseRecursive(string str)
        {
            if (str.Length > 0)
                return str[str.Length - 1] + ReverseRecursive(str.Substring(0, str.Length - 1));
            else
                return str;
        }
    }

class MainReverse
    {
        public static void Main(string[] args)
        {
            Console.Write("Enter the string: ");
            string s = Console.ReadLine();
            ReverseString rs = new ReverseString();
            Console.WriteLine("\nReverse: " + rs.Reverse(s));
            Console.ReadLine();
        }
    }

Refrences :
http://en.support.wordpress.com/code/posting-source-code/

Leave a comment

Filed under C#