The Dummies’ Guide to How to solve Problems with Extension Method

I am pretty much sure that, You have used Extension method in your program. Did you think to create your custom Extension method ?

If not then this article help you to create your own Extension method step by step.

Before jumping to direct practice let’s understand first what is extension method. So, an Extension method is created to simplify the code. It is a static method which represent as instance method. It accepts “this” keyword as a parameter.

If you see below example image you are not going to surprise as you have used this type of method.


Now, let me tell you more about the Extension method. As you now aware it is a static method & it accept “this” as a parameter so just need to add a “.” dot symbol with variable and all the existing method will be appear.

The question come to our mind how to create our own Extension method. So, it is simple and easy. We need to create a static class first and then that static class we can create our own Extension method.


Once you added a class in your solution specify the class as a static class and a static method in the class. In below example I am using static method with name  “MyStringCharacterLength”  if you see the below snap you will find in the parameter we are using this which is must for an extension method. We are not doing any fancy with this method it is a simple logic of calculating the length of the string.


Now once the extension method is created we can use this method using by a “.” dot symbol. Isn’t it easy let me show you the code.


When we run this code it will return the length of the string which provided as a input.

I hope a basic now you have a basic understanding of extension method. You can create your various method to use this and reduce your efforts in cases where you have to write similar logic again and again.

I recommend below site from where you can download existing Extension method and  use it.

I hope you have a clear view of extension method now.


LESS but it is more–CSS Preprocessor with ASP.NET


Now a days a “ CSS  pre processor “ is a very famous buzz word.  Although I am a web developer but still I am not always interested in writing CSS  don’t know why.

When I heard about css pre processor then I was curious to know what it exact about.

So let me share my thought here about CSS Preprocessor.

So a  CSS pre processor is a way to extend the CSS language and variables, functions and programming  stuff.

As a developer you will be more happy to have pre processor because it allows you to write code and also reduce the amount of css up to some extent.

There are many CSS  pre processor are exists in the market  like LESS, SASS,

Stylus,clay and many more.

Now Let me share here how to use LESS.css in your ASP.NET code.

Step 1:-  Add  Nuget package Less.js


once you added this package in your script folder you will get 2 new java script file with prefix less as shown below in figure


Step 2:- Now right click on content folder and add a new item which is LESS style sheet. This file will have extension .less



Step 3:-  Now you can write your LESS related code as shown in below snap


If you see above snap I declared  variable like @back-color , @font-color etc

and used in body.

Step 4: Now  add a web page and write following lines to enable LESS css.

<link href="Content/MyLessCss.less" rel="stylesheet/less" />
   <script src="Scripts/less-1.5.1.min.js"></script>


step 5:- Now in web.config we need to add following mime type


Or you can add this from IIS.

Step 6: Now we are good to go and can run  it


So we get the color according to variable which we declared.

It means we can play with the variables and can write the less code in programming way.

I hope this post will give a step to go further and I am sure you will deep dive in CSS pre processor soon.

Enjoy !!!

RJ !!

How easy to reduce efforts in retesting a web application?


Most of the time when you write code for a web application you need to test it again and again. You have to run a whole flow of positive or negative test cases to check whether your application is working or not.

Now suppose your application have 20 pages and you need to traverse each individual page and may be perform some operation and on each change of your development you need to perform same thing.

sometimes, this thing will irritate you and you will skip testing which may be harmful because most of the time it happens when you skipped something Smile you took a deep breath  and at that moment your application crashed Sad smile.

So , as a responsible developer we do not have to skip any test scenario but next question is how to reduce this effort which you feel boring sometime.

I can say we can reduce this effort by a installing a simple  Firefox add-in which is absolutely free. The add in “Selenium add in”

you can download it from

once you have installed this you will find the selenium icon near by search bar as shown below


when you click this icon you will get a selenium interface as shown below


The basic concept of this tool is what ever you will run in browser it has capability of recording those steps so it is just play button and pause button game, no rocket science. You can easily run and use this.

I am sure it will reduce your testing effort and when when selenium ide will play your test cases you can take a deep breath and enjoy your coffee and snacks.

I hope this tip may be helpful to you somewhere.

Happy Holidays.



MVC from Beginner to advance session by Indiandotnet


Dear All,

Thanks for attending session on 30th Nov 2014. I would like to say a big thanks to Abhishek Sapkale also who delivered the session and share knowledge with us.

We tried to  do go live in this seminar and some people joined also and enjoyed the live streaming.

Those who were not able to attend the session due to some reason, they can see the videos of session from below links

You can also watch presentation at slide share


I hope it might help you.


Rj !!!

How to create Web API ?

Dear Friends,

In Last article 

We have discussed what is Web API. Now in this article we will see how to create web API. So with out wasting much time lets start visual studio (In my case I am running VS 2013 web express).

So in my example I am creating a web API project for Friends. this API should return either all the friends or specific friend according to Id so lets start.

Step 1: Create a  new web project when you click on web project you will get following option. Select Web API option as shown in below screen shot.


You will get default project as below with defined folder structure


The main point here is to remember Model class should come in model folder & Controller class should come in controller folder

Step 2:- Once you click on Web API option project will open. Now Create a model (a simple class) with name Friend. this model class have basic friend’s property like his firstName, LastName,Id etc. as shown in below fig


Step 3:- Now create  a Friend controller so for this just add new item which is controller as shown in below fig


In the above option I have selected Web API 2 controller Empty template

things to remember here the name of controller class will be use later on in your API URL so select the name properly and the controller class name should followed by controller.

In my case I have created controller with following name =”FriendController.cs”. So now your project structure is as shown below


Step 4:- Now remember all the coding part need to be done here . I am creating two method here one method with name “GetAllFriends” and “GetFriendById”.

So as name suggest one will return list of all friends and one will return particular friend for a given id. If you see below instead of fetching data from database I have created a array of friends as shown.


Now in above fig you saw two method with different return type. Now concentrate on GetFriendByID It’s return type is HttpActionResult. so if you see below in that particular method the return type is OK which means status code 200. It means http response will be return in this method.

Now another interesting part is you can add different attribute with method like HTTPGET, HTTPPOST,HTTPDELETE etc Just see in below screen shot as shown below.


Now another interesting point is what if you want two attribute on same method then you can use below option which shown “AcceptVerbs”


Step 5:- Now our most part is done now you need to access web API but before accessing web API you need to check route and if something is missing their then you need to modify WebAPI config  which you will get in App_Start function. In my case I have added API/{controller}/{action}/{id} which was not exist earlier. as shown in below fig


Step 6:- Now we are good to go now just run the application and type in url http://localhost:yourport/API/Friend you will get list of all the friends as shown below


Now if you want to get specific friend with particular id then you have to write url like http://localhost:youport/API/Friend/1

You will get particular friend with that id as shown below



Isn’t it simple ?

I hope you understand how easy to create Web API. Now in next step we will learn how to consume the Web API.

Mean while you can create different web api.

So enjoy till than

Your host,


How to disable Right click on web page ?

Dear All,
Sometime, due to some security reference your application require to stop right click on web page.
In such case you need to write just simple code as shown below.

Right click disable

So now when you run your web page and right click you will get following message.

So just each code and you are good to go.

Hope you like it.

Thanks & Best Regards,
Rajat Jaiswal

How to create dynamic form using Javascript and Submit it in ASP.Net ?


Dear friends ,

sometimes you need to create dynamic form in . Let see below example to understand it more clearly.

Suppose on a  button click you want pass token value to a different  handler page then you need to write following lines

<script type="text/javascript">

function callPagePostBack(accessToken) {

var form = document.createElement("form");
            form.setAttribute("method", ‘post’);
            form.setAttribute("action", ‘LoginAuthentication.ashx’);

            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", ‘accessToken’);
            field.setAttribute("value", accessToken);




When you run above code you will find on LoginAuthentication.ashx folder you are getting accessToken there.


I hope you enjoyed this tutorial.

Thanks ,

Rajat Jaiswal

How to invoke a Java script after completion of server event of control ?


Dear All,

Sometime you fall in this situation where you need to invoke a java script just after your server event of control. Lets  understand with an example suppose you have a server control button on your web page now after clicking this button page will post back and everything is added in database and then after you need to show  Java script alert like Record is Saved successfully.

so to achieve this task you need to do following things

1.) Write a Javascript function for showing custom alert message  just like below

<script type="text/javascript">
        function onSuccessful() {

              alert(‘Data Saved Successfully’);


function onError() {

alert (‘Data not saved successfully’);


2) In server side button event you need to do following thing

protected void btnFaceBookLogin_Click(object sender, EventArgs e)
             if (CheckLogin())

ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "RegisterSuccess", "onSuccessful();", true);


else {

ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Registerfail", "onError();", true);


} catch (Exception ex) {




So when you compile it and run it after button click’s server side event javascript will fire according to checklogin  status.

Here the important note is to register the script with unique name.

I hope this will help you also.

Enjoy cheers 🙂

Rajat Jaiswal

How to Convert current date time different time zone (EST/PST/CST) in ASP.NET (C#) ?

Dear All,
Sometimes your application demands to covert date time in particular time zone.
.NET provided TimeZoneInfo class which help us in converting time in particular time zone.
Steps to utilize this is as follow
1) Convert time in any time zone firstly use UTC time.
2) Use TimeZoneInfo class to convert time zone from UTL to particular time

Below are some examples to utilize this

1) Convert time zone to EST (Eastern Standard Time)
DateTime EstDateTime = DateTime.UtcNow;
EstDateTime= TimeZoneInfo.ConvertTimeFromUtc(EstDateTime, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

2) Convert time zone to PST (Pacific Standard time)
DateTime PSTDateTime = DateTime.UtcNow;
PSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(PSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));

3) Convert time zone to Central Standard Time
DateTime CSTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time "));

4) Convert time zone to GMT Standard Time
DateTime GMTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"));

I hope this will helpful to you also.

Thanks & Best Regards,
Rajat Jaiswal

How to remove scroll bar from Fancybox when using Iframe?

Dear All,
Suppose you are using JQUERY  FancyBox  popup one of the best popup and showing iframe in it but you are facing issue of scrollbar. You want to avoid scrollbar from fancybox then you have to do following things and I hope it will resolve your problem too.
So here is the solution 
$(document).ready(function () {   
   'titleShow': false,               
'autoscale': false,               
'autoDimensions': false         

And in CSS you have to do following things
.fancybox-type-iframe .fancybox-inner {

overflow:hidden !important ;
height:500px !important;

It resolved my problem I hope it will resolve your problem too.

Thanks & Best Regards,
Rajat Jaiswal