Monday, November 11, 2013

New features in .NET 4.5


  • Async and wait 
  • Zip Compression
  • Regex timeout
  • Improvised garbage collector
  • Profile optimization (Improved startup performance)
  • Set default culture to App Domain  (helpful in working on multi threaded environment)
  • Array support more than two gigabyte size
  • Asynchronous HTTP Modules and Handlers.
  • New Request Validation features in Asp.Net 4.5

Saturday, August 24, 2013

What are the new features introduced in MVC4




  1. ASP.NET Web API
  2. Enhancements to default project Templates
  3. Mobile Project Template
  4. Display Modes
  5. JQuery Mobile
  6. View Switcher
  7. Browser Overriding
  8. Task Support For Asynchronous controller
  9. Empty Project template

FIND() selector in Jquery


To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.
find() lets you filter on a set of elements based on a selection you've already made. For example if you wanted to set the back-ground color to all the spans inside a div, you could write:

$('#testDiv').find('span').css('background-color', 'red');

We can do the same by using below syntax
$('#testDiv span').css('background-color', 'red');


Here “testDiv” is a div tag.


Find selector is a much faster comparative to above one.

Identifying the elements by attribute values in Jquery

$(‘element[attribute=”value”]’): Selects all elements that have the specified attribute with a value exactly equal to a specified value.
Ex:  $('span[id="spnTest1"]').css('background-color', 'red');

$(‘element[attribute^=”value”]’): Selects all elements that have the specified attribute with a value beginning with specified value. The comparison is case sensitive.
Ex: $('span[id^="span"]').css('background-color', 'blue');

$(‘element[attribute$=”value”]’): Selects all elements that have the specified attribute with a value ending with specified value. The comparison is case sensitive.
Ex: $('span[id$="test3"]').css('background-color', 'yellow');

$(‘element[attribute*=”value”]’): Selects all elements that have the specified attribute contains sub string of specified value. The comparison is case sensitive.
EX: $('span[id*="test"]').css('background-color', 'green');

Basic selectors in Jquery

Identifying the element by tag  name
Ex: $('p') -> selects all paragraphs in the document

Identifying the element by ID
Ex: $(‘#divUser’) -> selects a DOM element which contains ID as “divUser”.

Identifying  the element by class

Ex: $(‘.divUser’) -> selects a DOM element which contains class as “divUser”.

Why to go with Editor Templates instead of partial views in MVC?

The problem with partials is that they do not preserve the navigational context. This means that any input fields that you might have put inside this partial will have incorrect names and the default model binder will not be able to retrieve the values back when you POST.


To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.

Parse the Sql query with out executing it.

declare @sql nvarchar(max)
set @sql = 'select * FROM Students'
declare @testsql nvarchar(max)
declare @result int =1
set @testsql = N'set parseonly on; ' + @sql
BEGIN TRY
exec @result = sp_executesql @testsql
END TRY
BEGIN CATCH
PRINT 'ERROR’
END CATCH
Select @result
-- If it worked, execute it
if @result = 0
begin
exec sp_executesql @sql
end

Adding a custom Jquery function to check whether a element exists in a html page or not using Jquery

Please add the below code your custom .JS file

(function($) {
    if (!$.exist) {
        $.extend({
            exist: function(elm) {
                if (typeof elm == null) return false;
                if (typeof elm != "object") elm = $(elm);
                return elm.length ? true : false;
            }
        });
        $.fn.extend({
            exist: function() {
                return $.exist($(this));
            }
        });
    }
})(jQuery);

Usage
------------
// With ID
$.exist("#eleID");
// OR
$("#eleID").exist();

// With class name
$.exist(".class-name");
// OR
$(".class-name").exist();

// With just a tag // Probably not best idea as there will be other tags on the site
$.exist("div");
// OR
$("div").exist();

Friday, March 1, 2013

How to override IIS error pages with the custom pages in MVC

First we should turn off custom error pages in <system.web> section:


<system.web>
    <customErrors mode="Off" />
</system.web>

And then enable it <system.webServer> section:

<system.webServer>
    <!-- Custom Error Pages -->
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="404" path="/Error/404" responseMode="ExecuteURL" />
      <error statusCode="500" path="/Error" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>