How to create Generic Handlers Application in ASP.NET

By
HTTP Handlers were used in previous versions of visual studio such as 2002 and 2003.Because these versions did not provide any user-friendly methods for creating the Handlers.Generic Handlers is the easiest way to create a New HTTP Handler.Now we are using visual studio 2010,this makes easier to create the Handlers in asp.net application.Visual studio 2010 provided many user-friendly methods for creating the handlers.
There are some steps to create the Generic Handlers application which are given below:-
Step 1:- First open your visual studio-->File -->New -->Website-->Select ASP.NET Empty website-->open Solution Explore-->Add a New webform (home.aspx).

Step 2:-  open Solution Explorer --> Right click on Website-->Add New Item-->Select Generic Handler .ashx as shown below -->click Add Button.


create

Step 3:- Write the following codes in the Generic Handler.ashx page.

<%@ WebHandler Language="C#" Class="GenericHandler" %>
using System;
using System.Web;

public class GenericHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        ManageForm(context);
    }
 
    public void ManageForm(HttpContext context)
 {        
  context.Response.Write("<html><body><form>");
  if (context.Request.Params["NewFeature"] == null)
  {
   context.Response.Write("<h2>Select your category value from dropdwon list</h2>");
            context.Response.Write("<select name='NewFeature'>");
            context.Response.Write("<option>General</option>");
   context.Response.Write("<option>OBC</option>");
   context.Response.Write("<option> SC </option>");
   context.Response.Write("<option>ST</option>");
   context.Response.Write("<option> PD </option>");
            context.Response.Write("<option> OTHERS </option>");
   context.Response.Write("</select>");
   context.Response.Write("<input type=submit name='Submit' value='Submit'></input>");
   context.Response.Write("</br>");
  }
      
  if (context.Request.Params["NewFeature"] != null)
  {
  context.Response.Write("Hi, you are selected: ");
  context.Response.Write(context.Request.Params["NewFeature"]);
  context.Response.Write(" Catogery,change it if wrong</br>");            
  }
  context.Response.Write("</form></body></html>");
 }
    public bool IsReusable {
        get {
            return false;
        }
    }
}

Step 4:- Now Run Generic Handler.ashx file(not home.aspx)-->for this,First open Solution Explorer --> Right click on Generic Handler.ashx -->Click  Set As Start Page-->Then  Generic Handler.ashx  page will run first.


handler_output

Step 5:- Now click Submit button -->you will see a specific handler output as shown below:-



Note:- HTTPHandler is the older feature of asp.net technology.Now latest handler is used ,called Generic Handler.  
For More:-
    1. Date handling in SQL Server
    2. Create setup file with sql Database
    3. Project on E-post System
    4. File Handling Real application
    5. Stored procedure and Function
    6. String and String Builders 
    7. Make Custom Registration and login page
    8. Create .dll file for asp.net application
    9. Dataset and Date Adapter
    10. Default Constraints on Sql Server

For whole Application 
     Download

0 comments:

Post a Comment

Powered by Blogger.