Monday, March 25, 2013

ASP.NET 4.5 TextBox TextMode Property

Right now everybody is talking about HTML5 and its contains lots of new features like web sockets, canvas, new intput types with validation etc.

ASP.NET 4.5 text mode property enhancement:

With HTML5 new input types is going to be one of coolest feature and in future more and more people are going to use that feature. So in 4.5 development team given a support via TextMode property enhancements.

In earlier versions of ASP.NET we used have only three properties for TextMode property of textbox control.
  1. MultiLine- for multiline textbox.
  2. Password- for password textbox
  3. SignleLine –for single line textbox
With ASP.NET 4.5 you are going to have tons of options with TextMode property.
  1. Color- for Color entries
  2. Date-  for date entries. You can enter dates only
  3. DateTime – for datetime entries with respect to local time zone.
  4. DateTimeLocal- for datetime entries with respect to local time zone.
  5. Email- for email address
  6. Month- for month and year entry.
  7. Number- for  entering numeric values.
  8. Range- for containing range between two numbers.
  9. Search- for search field. A search field is like regular text fields
  10. Tel- for telephone number.
  11. Url- for website url entries. It will only contain urls.
  12. Week- for entering weeks and year.
Saturday, March 23, 2013

Difference between All and Any operator in linq

In this post we are going to learn about difference between ‘All’ and ‘Any’ operator in Linq.

Difference between ‘All’ and ‘Any’ operator:

All operator checks whether all elements have met specific conditions or not while Any operator check whether there is any elements exist in collection or not?

So what we are waiting for Let’s take a example.
using System;
using System.Linq;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            int[] intArray = {1,2,3,4,5};
            bool result = intArray.All(i => i > 2);
            result = intArray.Any();
In the above example you can see that I have created an integer array and then checked with both all and any operator. In first condition I have checked that whether elements are greater then 2 or not and same way I have checked with any operator that its contains any element or not?

Now let’s run that example. To see how its works.
Friday, March 22, 2013

My blog post appears on community spot light

Once again my blog post about CRUD operations with and petapoco appears on the Microsoft official website. I would like to thank you all for specially Jon Galloway and team.


A big thank you for every one for supporting me.
Saturday, March 16, 2013

All operator in linq

Few days back I came across “All” operator in Linq. I thought it will be good idea to write a blog post about it and share it with community.

All operator in linq:

It’s almost similar to select it returns all the element in the input sequence with matching condition in given predicate. Following is syntax for All.
public static bool All<TSource>( 
this IEnumerable<TSource> source, 
Func<TSource, bool> predicate)

It check the condition whether all the elements on collection matches given criteria and based on that it will return bool value.  It can be useful in scenario where we need to do some kind of validation whether all the elements of collection matches with certain condition or not.

So Let’s take a simple example. Following is a code for that.
using System;
using System.Linq;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            int[] intArray = {1,2,3,4,5};
            bool result = intArray.All(i => i > 2);
            result = intArray.All(i => i < 6);

Thursday, March 14, 2013

CRUD operations with PetaPoco and ASP.NET MVC

In this post we are going to see how we can do CRUD operations with ASP.NET MVC and PetaPoco Micro ORM.

What is PetaPoco?

Petapoco is a tiny ORM developed by topten software. As per them it’s a tiny, fast, single-file micro-ORM for .NET and Mono.
  • Like Massive it's a single file that you easily add to any project
  • Unlike Massive it works with strongly typed POCO's
  • Like Massive, it now also supports dynamic Expandos too - read more
  • Like ActiveRecord, it supports a close relationship between object and database table
  • Like SubSonic, it supports generation of poco classes with T4 templates
  • Like Dapper, it's fast because it uses dynamic method generation (MSIL) to assign column values to properties

Features of PetaPoco:

As per topten software it contains following features.
  • Tiny, no dependencies... a single C# file you can easily add to any project.
  • Works with strictly undecorated POCOs, or attributed almost-POCOs.
  • Helper methods for Insert/Delete/Update/Save and IsNew
  • Paged requests automatically work out total record count and fetch a specific page.
  • Easy transaction support.
  • Better parameter replacement support, including grabbing named parameters from object properties.
  • Great performance by eliminating Linq and fast property assignment with DynamicMethod generation.
  • Includes T4 templates to automatically generate POCO classes for you.
  • The query language is SQL... no weird fluent or Linq syntaxes (yes, matter of opinion)
  • Includes a low friction SQL builder class that makes writing inline SQL much easier.
  • Hooks for logging exceptions, installing value converters and mapping columns to properties without attributes.
  • Works with SQL Server, SQL Server CE, MySQL, PostgreSQL and Oracle.
  • Works under .NET 3.5 or Mono 2.6 and later.
  • Experimental support for dynamic under .NET 4.0 and Mono 2.8
  • NUnit unit tests.
  • OpenSource (Apache License)
  • All of this in about 1,500 lines of code
Wednesday, March 13, 2013

Default focus and default button in

Sometimes ago a friend ask me how to put default focus and default button in ASP.NET. He was not knowing that there is property for that in form tag in I thought it will be good idea to write a blog post about that.So those who are not aware of this feature can get an idea for that.

In some cases we need to have default button and default focus. For example take a example of a shopping cart registration form. Where you need to have default focus into the first textbox if you contain list of textboxes over there. Same way you can have more then one button on forms for example save and cancel so once user press enter which button should be pressed. On above both scenario this Default button and default features can come very handy.

From 2.0, The form tag has this two properties DefaultButton and DefaultFoucs where you can set the Id of control that you need as default button and same way you need to put Id of a control for default focus.
Sunday, March 10, 2013

How to consume ASP.NET WebAPI from jQuery

Before some months Microsoft has launched WebAPI framework for building and consuming HTTP services. This WebAPI can be called from anything like from mobile sites to JavaScript anything. I thought it will be a good idea to call a WebAPI from jQuery.

In this post I am going to explain how to consume ASP.NET WebAPI from jQuery.

Creating a basic WebAPI:

To create a web API you need to install ASP.NET MVC 4.0 and then you create a new project for MVC .

How to Create Webp API in Visual studio 2012

Now once you click Ok. It will ask for type of project. You want to create you need to select Web API there.
Friday, March 8, 2013

Dependency graph in visual studio 2012- Understand your code better.

Today I came across a new feature of visual studio 2012 called Dependency Graph in visual studio 2012. I thought it will be good Idea to write a blog post about this.

I have written list of visual studio 2012 features post. You can find this at my Visual Studio 2012 page.

What is Dependency Graph?

Dependency graph help you visualize how your code is written and organized and provide view on code dependencies. This is very useful when you are working with a code that you have not written. With the dependency graph you can easily get an idea of code written by others in a application.

How to create Dependency Graph:

You can easily create dependency graph via architecture menu –>Generate Dependency graph. You will also presented to two options like below.
  1. For Solution
  2. For Include file.
Thursday, March 7, 2013

SelectMethod in ASP.NET 4.5 Model binding

New version of ASP.NET provides lots of way of binding data to the data controls like Grid View, Repeater etc. You can now bind this controls with strong type. I have earlier written a blog post about How we can use Model binding with ASP.NET 4.5 and Visual Studio 2012.

SelectMethod in ASP.NET 4.5:

In 4.5, It is also possible to bind controls with SelectMethod attribute. This method specify the data that you want to bind with data controls like grid view and repeater controls.

So what we are waiting for?? Let’s take an simple example. I have create a basic model class “Employee” like below.
public class Employee
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
This class contains three properties EmployeeId,FirstName and LastName. Now I have created one method to get a generic list of employee model like following.
Wednesday, March 6, 2013

Telerik JustCode review

Visual Studio is a great IDE and  allow developers to design and code anything from windows application to web application. But it does not have a much code refactoring features so You need to have third party add in to make this happen. Telerik JustCode is one of them.

Recently I was contacted by Telerik team to review Telerik JustCode. So I installed Telerik Just code in my machine and I have used it for few days and Here is the my first impressions.

Things that I like about Telerik JustCode:

  1. It does not have impact on the Visual Studio load time.
  2. It does not change any theme or UI for the Visual Studio.
  3. Performance is much better then it’s competitors. It does not slow down visual studio while you were using it.
  4. Its not overwriting all things in Visual Studio like visual studio shortcuts.
  5. Another things its competitively priced then its competitors.
  6. Cloud Sync of your settings so you don’t have to worry about loosing your settings.
  7. Almost got all the features of code refactoring and code creation which are available with tools.
  8. Does not have annoying popups for suggestions or code refactoring.

Tip- InProc session state was not working with IIS7.5

In this post I am going to explain about reason for InProcsessionState was not working with IIS 7.5.


Yesterday in one of my PC I got updated IIS 7.5 and suddenly after updating the IIS my ASP.NET application session state stopped working. It was a very weird behaviour and after doing some R and D I have found that my worker process per application was more then one.

That was the reason for the  session state was not working as “InProc” session state is using IIS memory to manage sessions.  You can find more information about this in following link.


There are two ways of resolving this problem.

1) You can use other session state mode like State Server or SQL server which supports multiple worker processes.
Sunday, March 3, 2013

Page inspector in Visual Studio 2012

In this blog post we are going to learn about a new feature of Visual Studio 2012 called “Page Inspector”.

I have written  whole series about new features of Visual Studio 2012. This post will also be part of it. You can find all post related to Visual Studio at my Visual Studio 2012 page. Following is a link for that.

Visual Studio 2012 Feature Series

What is Page Inspector:

Page inspector is a great tool to inspect your page in Visual Studio itself. In other words, You can use Page Inspector as a browser and inspect your pages in Visual Studio itself. It’s really slow a common problem you can diagnose your page in visual studio itself. You can see where you UI comes from and even you can look into your page in HTML.

Video about different searching options in visual studio 2012

I have created a video tutorial for Visual studio 2012. Where I have shown different kind of searching options.

Hope you like it. Stay tuned for more..

Shout it

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews