Sunday, September 30, 2012

HTML5 New Attributes

HTML5 has added new attributes.Today, we would have brief overview of all the new attributes and elements added to HTML5.

Before moving ahead, to enable HTML5 on your web page, you need to add following line of code in HTML side

Placeholder attributes gives the watermark to the elements. So, this in turn tells you what we are expecting from the user and user too knows what needs to be entered in the textbox.

HTML to be added to design view to enable placeholder for textbox

Below is the final output you would see

REQUIRED Attribute
HTML5 has added new attribute named as 'required'. Setting this attribute makes the textbox a mandatory field and that cannot be left empty.
With addition of required attribute, you now don't have to write additional javascript to check whether the field is empty or not. Furthermore, if the field is left empty it alerts the user with message to fill out that particular field.

Lets see what needs to be done to get this feature in our application. Please add the following text in your design/HTML side

Below is the screenshot of what will be shown to user if the textbox is left empty and we simply click Submit button

Hope this article gives to some overview of new HTML5 attributes.

Sunday, September 16, 2012

How does ASP.NET process the request

1) When we enter the URL, page request goes to IIS

2) IIS checks the ISAPI(Internet Server Application Programming Interface) extension of the request

3) If extension is .aspx then request is forwarded to ASP.NET engine

4) ASP.NET engine checks whether the Application Domain exists for the request

·         If yes, request is forwarded to that App Domain

·         If not, it creates the App Domain and then the request is forwarded to it

5) ASP.NET engine creates core objects for

·         HTTPContext

·         HTTPRequest

·         HTTPResponse

6) Checks whether HTTPApplication object exists

·         If yes, pass on the core objexts to HTTPApplication object

·         If not, create the HTTPAppplication object and pass on the core objects to it

7) After this, HTTPApplication object process the request. It executes Begin,Authentication and Authorization events

8) After this request is passed to Page. Page events and complete page cycle will run
9) After running the Page cycle, request is again forwarded to HTTPApplication object and HTTPApplication will cleanup and pass on the response to user  

Block the website on your local computer

Follow the following basic steps

  • Open the file named Hosts under Windir:(C: )\Windows\System32\drivers\etc. Before opening the file, kindly check whether you have administrative access on the file. If not then grant yourself access.

  • Add entry to the file of the website for which you want access to be restricted

  • Save this and facebook will not be accessible

Thursday, September 13, 2012

Page Inspector in ASP.NET 4.5

Page Inspector is a new tool that brings browser diagnostics tools into Visual Studio and provides an integrated experience between the browser, ASP.NET, and source code.

Page Inspector enables you to easily quickly diagnose issues

Using Page Inspector, you can see what elements in the source files (including server-side code) have produced the HTML markup that is rendered to the browser.

Page Inspector also let you modify CSS properties and DOM element attributes and see the changes reflected immediately in the browser. 

To work with Page Inspector, simply right click on the project in solution explorer and select ‘View in Page Inspector’

This would open the Startup page of the project

Select the ‘Inspect’ and move the cursor to any of the code line. You will see that when you move cursor, in other screen it would highlight the section which is generating the html markup in the browser.

You can change the data according to your ease.
As and when you change data, Page Inspector would tell you that some files have been changed and it would require refresh the browser to have the updated HTML markup in the browser as shown below

Difference between Delete and Truncate Command

DELETE Command
  • Delete Command always delete data from TABLE on basis of WHERE command specified in the SQL Query
  • Delete Command doesn't resets the identity coulmn of the Table
  • Delete command can be rolled back
  • Delete comand is DML(Data Manipulation Language) statement.
  • Delete command is slower as compared to Truncate command
  • Delete command can initiate the TRIGGER

  • Truncate command deletes entire table
  • Truncate command resets the identity column of the table
  • Truncate command cannot be rolled back
  • Truncate command is DDL(Date Definition Language) statement.
  • Truncate command is faster as compared to Delete command
  • Truncate command cannot initiate the TRIGGER

Bundling and Minification

Basics of Bundling and Minification
As more and more people use mobile devices to surf the web, it is becoming increasingly important that the websites and apps we build perform well with them. We’ve all tried loading sites on our smartphones – only to eventually give up in frustration as it loads slowly over a slow cellular network.  If your site/app loads slowly like that, you are likely losing potential customers because of bad performance.  Even with powerful desktop machines, the load time of your site and perceived performance can make an enormous customer perception.
Most websites today are made up of multiple JavaScript and CSS files to separate the concerns and keep the code base tight. While this is a good practice from a coding point of view, it often has some unfortunate consequences for the overall performance of the website.  Multiple JavaScript and CSS files require multiple HTTP requests from a browser – which in turn can slow down the performance load time. 

I have placed following line of code in design
    <script src="scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="scripts/all.js" type="text/javascript"></script>
    <script src="scripts/references.js" type="text/javascript"></script>
    <script src="scripts/jquery-1.6.2-vsdoc.js" type="text/javascript"></script>
    <script src="scripts/jquery-1.6.2.js" type="text/javascript"></script>
    <script src="scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
    <script src="scripts/modernizr-2.0.6-development-only.js" type="text/javascript">

Below I’ve opened a local website in IE9 and recorded the network traffic using IE’s built-in F12 developer tools.  Each file is currently requested separately by the browser and returned by the server, and the process can take a significant amount of time proportional to the number of files in question.

ASP.NET is adding a feature that makes it easy to “bundle” or “combine” multiple CSS and JavaScript files into fewer HTTP requests. This causes the browser to request a lot fewer files and in turn reduces the time it takes to fetch them
The next release of ASP.NET is also adding a new feature that makes it easy to reduce or “minify” the download size of the content as well.  This is a process that removes whitespace, comments and other unneeded characters from both CSS and JavaScript. The result is smaller files, which will download and load in a browser faster.
Simply replace the lines of code with
  <script src="scripts/js" type="text/javascript"></script>
Remember js – indicates the extension of files that needs to be bundled and minified
Look at the result

Any number of directories/sub-directories supported
In the example above we just had a single “Scripts” and “Styles” folder for our application.  This works for some application types (e.g. single page applications).  Often, though, you’ll want to have multiple CSS/JS bundles within your application – for example: a “common” bundle that has core JS and CSS files that all pages use, and then page specific or section specific files that are not used globally.
You can use the bundling/minification support across any number of directories or sub-directories in your project – this makes it easy to structure your code so as to maximize the bunding/minification benefits.  Each directory by default can be accessed as a separate URL addressable bundle. 
There is BundleConfig.cs defined under /App_Start folder. We can define our custom scripts/style there .
Simply add

   bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(


bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(

After this reference the same in design page like
<script src="/bundles/WebFormsJs"></script>


Monday, September 10, 2012

ASP.NET 4.0 and VS 2010 New features

Today, i read very interesting article on new features of C# 4.0 and VS 2010.Below is the link for the article

Go through the article.

Till the time enjoy the life and happy coding !!

Sunday, September 9, 2012

Multiple File Upload in ASP.NET 4.5

ASP.NET 4.5 has come with very nice feature and one of the new feature is uploading of multiple files at one instant.So, let's move forward and get overview of this new feature.

Simply drap and drop the FileUpload tool in design view

  <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"/>

You will see new property has been added to FileUpload control named as 'AllowMultiple'.
Simply set this property to TRUE to enable the multiple file upload feature.

Let's move forward to view some code
I have added fileupload control and one button to view the names of file uploaded as well as save those files in some desired location.

HTML code

Code Behind File

Hope you have learnt one more new feature of ASP.NET 4.5.
In case of any questions, please get back to me.

Till the time enjoy life and coding !!

Saturday, September 8, 2012

What is OAuth

OAuth support is now available in ASP.NET 4.5.Today, we would get overview of OAuth.


  •  OAuth is an authorization protocol - or in other words, a set of rules - that allows a third-party website or application to access a user’s data without the user needing to share login credentials.
  • OAuth's open-source protocol enables users to share their data and resources stored on one site with another site under a secure authorization scheme based on a token-based authorization mechanism.
  • With OAuth, resources stored on one website can be shared or accessed by a user once he is authenticated via OAuth. There is no need for the user to create a new account on the website.
  • OAuth operates much like a client/server computing model, where a primary website storing the user resources acts as a server and the website or application accessing that data is a client. The primary website establishes an OAuth interface (otherwise called an API) and secret key for the requesting website as a means of establishing a session to validate the user. Once the user requests access to the data or resources of the client website, he or she takes a side trip and is forwarded to the login procedure of the primary website, at which time the user provides his or her login credentials. Upon successful authentication there, an authorization token is sent from that primary website to the requesting website as an acknowledgment of authentication - allowing the user the access of data or other resources originally requested.

Color Theme Editor in Visual Studio 2012

Visual Studio 2012 provides one default gray color and also all the Menu items are in CAPS.
There is color theme editor which can change the default theme of Visual Studio 2012 and you can select and even modify the color theme.
Ok let get started...

  • To execute this file open the .vsix in Visual Studio. I had both Visual Studio 2010 and 2012 on my laptop so i selected 'Microsoft Visual Studio Version Selector'

  • Once the file is installed, open the Visual Studio 2012 and you would view new menu item named as 'THEME'

  • You can select different themes listed and change the default gray color of Visual Studio 2012.

Hope you liked this short article.

Till time enjoy the life and coding !!

Friday, September 7, 2012

New HTML5 snippets

ASP.NET 4.5 added support for HTML5 snippets.
HTML5 introduced more than 25 new semantic tags. Visual Studio already had IntelliSense support for these tags, but Visual Studio 2012 makes it faster and easier to write markup by adding some corresponding snippets, like the ones for the audio and video tags.
To invoke the snippet, press Tab twice when the element is selected in IntelliSense:

 <audio controls="controls">
            <source src="file.mp3" type="audio/mp3" />
            <source src="file.ogg" type="audio/ogg" />

This produces a snippet that you can customize.

Automatic renaming of matching tag when you rename an opening or closing tag

If you rename an HTML element (for example, you change a div tag to be a header tag), the corresponding opening or closing tag also changes in real time.
        <audio controls="controls">
            <source src="file.mp3" type="audio/mp3" />
            <source src="file.ogg" type="audio/ogg" />

This helps avoid the error where you forget to change a closing tag or change the wrong one.

Smart indent

When you press Enter while inside an empty HTML element, the editor will put the insertion point in the right place:
If you press Enter in this location, the closing tag is moved down and indented to match the opening tag. The insertion point is also indented:

Hope you liked this blog.

Till the time enjoy your life and coding !!

Thursday, September 6, 2012

ASP.NET 4.5 - Project Sharing Between Visual Studio 2010 and Visual Studio 2012

Until Visual Studio 2012 Release Candidate, opening an existing project in a newer version of Visual Studio launched the Conversion Wizard. This forced an upgrade of the content (assets) of a project and solution to new formats that were not backward compatible. Therefore, after the conversion you could not open the project in the older version of Visual Studio.

Now with Visual Studio 2012, project sharing is possible between VS 2010 and VS 2012.
This means that if you open a 2010 project in Visual Studio 2012 , you will still be able to open the project in Visual Studio 2010 SP1.

Note: A few types of projects cannot be shared between Visual Studio 2010 SP1 and Visual Studio 2012 Release Candidate. These include some older projects (such as ASP.NET MVC 2 projects) or projects for special purposes (such as Setup projects).

When you open a Visual Studio 2010 SP1 Web project for the first time in Visual Studio 11 Beta, the following properties are added to the project file:
  • FileUpgradeFlags 
  • UpgradeBackupLocation 
  • OldToolsVersion 
  • VisualStudioVersion 
  • VSToolsPath 

   Hope you like this new features. Till the time enjoy the life and coding !!

ASP.NET 4.5 New Features

Microsoft has recently launched ASP.NET 4.5. So, I would be discussing various ASP.NET 4.5 new features. I would be regularly updating this blog with new features link.
Following are the links
Hope this article of mine would make you familiar with Visual Studio 2012 new features.Stay tuned to my blog to read new articles.

Till the time enjoy your life and coding !!

Nullable Types

Using Nullable Types

This is my first post. I would be posting many .NET post in coming days.
Today we would be learning what are Nullable Types in .NET

Nullable types can represent all the values of an underlying type, and an additional null value. 
Nullable types are declared in one of two ways:
System.Nullable<T> variable
T? variable
T is the underlying type of the nullable type. T can be any value type including struct; it cannot be a reference type.

For an example of when you might use a nullable type, consider how an ordinary Boolean variable can have two values: true and false. There is no value that signifies "undefined". In many programming applications, most notably database interactions, variables can occur in an undefined state. 

For example
A field in a database may contain the values true or false, but it may also contain no value at all. Similarly, reference types can be set to null to indicate that they are not initialized.

Any value type may be used as the basis for a nullable type. For example:
int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = 'a';
int?[] arr = new int?[10];

Each instance of a nullable type has two public read-only properties:
HasValue is of type bool. It is set to true when the variable contains a non-null value.
If HasValue is true, Value contains a meaningful value. If HasValue is false, accessing Value will throw a InvalidOperationException.

Lets consider an example

In this example, the HasValue member is used to test whether the variable contains a value before it tries to display it.

int? x = 10;
if (x.HasValue)

Testing for a value can also be done as in the following example:
int? y = 10;
if (y != null)

A nullable type can be cast to a regular type, either explicitly with a cast, or by using the Value property. For example:
int? n = null;

//int m1 = n;      // Will not compile.
int m2 = (int)n;   // Compiles, but will create an exception if n is null.
int m3 = n.Value;  // Compiles, but will create an exception if n is null.

A variable of nullable type can be set to null with the null keyword, as shown in the following example:
int? n1 = null;

The conversion from an ordinary type to a nullable type, is implicit.
int? n2;
n2 = 10;  // Implicit conversion.

These operators produce a null value if the operands are null; otherwise, the operator uses the contained value to calculate the result. For example:
int? a = 10;
int? b = null;

a++;         // Increment by 1, now a is 11.
a = a * 10;  // Multiply by 10, now a is 110.
a = a + b;   // Add b, now a is null.

When you perform comparisons with nullable types, if the value of one of the nullable types is null and the other is not, all comparisons evaluate to false except for != (not equal). It is important not to assume that because a particular comparison returns false, the opposite case returns true. In the following example, 10 is not greater than, less than, nor equal to null. Only num1 != num2 evaluates to true.


int? num1 = 10;
int? num2 = null;
if (num1 >= num2)
    Console.WriteLine("num1 is greater than or equal to num2");
    // This clause is selected, but num1 is not less than num2.
    Console.WriteLine("num1 >= num2 returned false (but num1 < num2 also is false)");

if (num1 < num2)
    Console.WriteLine("num1 is less than num2");
    // The else clause is selected again, but num1 is not greater than
    // or equal to num2.
    Console.WriteLine("num1 < num2 returned false (but num1 >= num2 also is false)");

if (num1 != num2)
    // This comparison is true, num1 and num2 are not equal.
    Console.WriteLine("Finally, num1 != num2 returns true!");

// Change the value of num1, so that both num1 and num2 are null.
num1 = null;
if (num1 == num2)
    // The equality comparison returns true when both operands are null.
    Console.WriteLine("num1 == num2 returns true when the value of each is null");

/* Output:
 * num1 >= num2 returned false (but num1 < num2 also is false)
 * num1 < num2 returned false (but num1 >= num2 also is false)
 * Finally, num1 != num2 returns true!
 * num1 == num2 returns true when the value of each is null

An equality comparison of two nullable types that are both null evaluates to true.

Nullable types have the following characteristics:
·             Nullable types represent value-type variables that can be assigned the value of null.
·             The syntax T? is shorthand for Nullable<T>, where T is a value type. The two forms are interchangeable.
·             Assign a value to a nullable type just as you would for an ordinary value type, for example int? x = 10; or double? d = 4.108. A nullable type can also be assigned the value null: int? x = null.
·             Use the Nullable<T>.GetValueOrDefault method to return either the assigned value, or the default value for the underlying type if the value is null, for example int j = x.GetValueOrDefault();
·             Use the HasValue and Value read-only properties to test for null and retrieve the value, as shown in the following example: if(x.HasValue) j = x.Value;
·                 The HasValue property returns true if the variable contains a value, or false if it is null.
·                 The Value property returns a value if one is assigned. Otherwise, a System.InvalidOperationException is thrown.
·                 The default value for HasValue is false. The Value property has no default value.
·                 You can also use the == and != operators with a nullable type, as shown in the following example: if (x != null) y = x;
·             Use the ?? operator to assign a default value that will be applied when a nullable type whose current value is null is assigned to a non-nullable type, for example int? x = null; int y = x ?? -1;

The ?? operator defines a default value that is returned when a nullable type is assigned to a non-nullable type.

int? c = null;

// d = c, unless c is null, in which case d = -1.
int d = c ?? -1;

This operator can also be used with multiple nullable types. For example:

int? e = null;
int? f = null;

// g = e or f, unless e and f are both null, in which case g = -1.
int g = e ?? f ?? -1;