title: How to Connect two Generic Handler c# asp.net Generic_Handler.ashx and Search.ashx
body: <p>How to Connect two Generic Handler c# asp.net  Generic_Handler.ashx  and Search.ashx
                          This is my two handlers if it is possible to connect two handlers in ASP.Net
                          Please Help any one** </p>
  
  <p><strong>Generic_Handler.ashx</strong></p>
  
  <pre><code>        &lt;%@ WebHandler Language="C#" Class="Generic_Handler" %&gt;
  
           using System;
           using System.Web;
           using System.Data.SqlClient;
           using System.Configuration;
  
           public class Generic_Handler : IHttpHandler 
           {
                 public void ProcessRequest (HttpContext context) 
                 {
                      string id = context.Request.QueryString["ID"];
                      byte[] bytes;
                      string FileType;
                      string strConnString = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
                      using (SqlConnection con = new SqlConnection(strConnString))
                      {
                          using (SqlCommand cmd = new SqlCommand())
                          {
                               cmd.CommandText = "select Video, FileType from TBL_YouTube where ID=@ID";
                               cmd.Parameters.AddWithValue("@ID", id);
                               cmd.Connection = con;
                               con.Open();
                               SqlDataReader sdr = cmd.ExecuteReader();
                               sdr.Read();
                               bytes = (byte[])sdr["Video"];
                               FileType = sdr["FileType"].ToString();
                               con.Close();
                            }
                      }
                      context.Response.Clear();
                      context.Response.Buffer = true;
                      context.Response.AppendHeader("Content-Disposition", "attachment; ID=" + id);
                      context.Response.ContentType = FileType;
                      context.Response.BinaryWrite(bytes);
                      context.Response.End();
                }
  
               public bool IsReusable
               {
                      get 
                      {
                          return false;
                      }
              }
  
           }
  </code></pre>
  
  <p><strong>Search.ashx</strong></p>
  
  <pre><code>            &lt;%@ WebHandler Language="C#" Class="Search" %&gt;
  
              using System;
              using System.Web;
              using System.Data.SqlClient;
              using System.Text;
  
              public class Search : IHttpHandler 
              {
  
                  public void ProcessRequest (HttpContext context) 
                  {
                        //context.Response.ContentType = "text/plain";
                        //context.Response.Write("Hello World");
                          string searchText = context.Request.QueryString["q"];
                          SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Videos;Integrated Security=True");
                          con.Open();
                          SqlCommand cmd = new SqlCommand("select FileName from TBL_YouTube where FileName Like @Search + '%'", con);
                          cmd.Parameters.AddWithValue("@Search", searchText);
                          StringBuilder sb = new StringBuilder();
                          using (SqlDataReader dr = cmd.ExecuteReader())
                          {
                              while (dr.Read())
                              {
                                   sb.Append(string.Format("{0},{1}", dr["FileName"], Environment.NewLine));
                              }
                           }
                           con.Close();
                           context.Response.Write(sb.ToString());
                  }
  
                   public bool IsReusable 
                   {
                        get 
                        {
                            return false;
                        }
                   }
  
             }
  </code></pre>