Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 .NET4 ASP:NET
there is  one handler
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.IO;
using System.Data.SqlClient;
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);
            connection.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();
            //Get Image Data
            byte[] file = (byte[])reader["Image"];
            reader.Close();
            connection.Close();
            memoryStream.Write(file, 0, file.Length);
            context.Response.Buffer = true;
            context.Response.BinaryWrite(file);
            memoryStream.Dispose();
        }}
     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 1:34am
Comments
Devang Vaja at 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
0 Sergey Alexandrovich Kryukov 6,775
1 OriginalGriff 6,696
2 CPallini 5,345
3 George Jonsson 3,599
4 Gihan Liyanage 2,751


Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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