Click here to Skip to main content
12,816,406 members (29,494 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET .NET C#4.0 .NET4
there is  one handler
<%@ WebHandler Language="C#" Class="Handler" %>

public class Handler : IHttpHandler 
   public string GetConnectionString()
        return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
    public void ProcessRequest (HttpContext context)
        string id = context.Request.QueryString["id"]; 
        if (id != null)
        {    MemoryStream memoryStream = new MemoryStream();
            SqlConnection connection = new SqlConnection(GetConnectionString());
            string sql = "SELECT * FROM TblImages WHERE Id = @id";
            SqlCommand cmd = new SqlCommand(sql, connection);
            cmd.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = cmd.ExecuteReader();
            //Get Image Data
            byte[] file = (byte[])reader["Image"];
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
     public bool IsReusable {
        get {
            return false;    }   }}

and there is form with dropdownlist with values and there is event
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
          Image1.ImageUrl = "Handler.ashx?id=" + DropDownList1.SelectedItem.Value;                       GetImageInfo(DropDownList1.SelectedItem.Value);

application is running with no error but i have one question that howcome in "id"(in handler code)value gets 1,2 or 3 (as per dropdownlist items) as qhen i run the url on browswer have only http://localhost:60686/server_controls/2.%20image_retrieving_database.aspx" then how it gets value fetched in context.Request.QueryString["id"];
pls tell regards
Posted 19-Feb-13 2:34am
Devang Vaja 19-Feb-13 7:49am
hey in selected index change You are calling handler in image url...
when handler is called the querystring is not passed but only request goes...
querystring is passed when request is go from 1 page to another and querystring is always passed in response.redirect("?a="++"); statement
Shivani ji....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100