2012-02-17 12 views
0

私のページでは、私は同じIDを持つ2つの画像を表示しようとしています。そのために、2つのイメージコントロール(imgX、imgY)があります。イメージコントロールにイメージを書き込むには、HttpHandler(ashx)を使用しています。イメージごとにHttpHandler(ashx)を作成する必要はありますか?

imgPhoto.ImageUrl = "Image.ashx?EmpBadge=" & Session("EmpBadge") 
imgSign.ImageUrl = "Image.ashx?EmpBadge=" & Session("EmpBadge") 

そしてASHXで:

私の問題は、私は両方のコントロール(imgX、imgY)ページのLoadイベントで

に追加同じ画像を取得しています、これは私のコードであるということです

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 
     Try 
      Dim imageId As String = context.Request.QueryString("EmpBadge") 
      Dim drPhoto As SqlDataReader 
      Dim param(1) As SqlParameter 
      param(1) = New SqlParameter("@EmpBadge", imageId) 
      drPhoto = IMSIndia.ExecuteReaderWithParam("SpGetPhotoAndSignature", param) 
      If drPhoto.HasRows Then 
       While drPhoto.Read() 
        context.Response.ContentType = "image/" & drPhoto("PhotoType") 
        context.Response.BinaryWrite(DirectCast(drPhoto("Photo"), Byte())) 
        context.Response.ContentType = "image/" & drPhoto("Signaturetype") 
        context.Response.BinaryWrite(DirectCast(drPhoto("Signature"), Byte())) 
       End While 
      End If 
     Catch ex As Exception 

     Finally 
      If IMSIndia.con.State = ConnectionState.Open Then 
       IMSIndia.ConnectionClose() 
      End If 
     End Try 
    End Sub 

ありがとうございました。

+0

「imagetype = photo」のような別のクエリー文字列を渡して、単純なif-elseを使って 'ProcessRequest'のコントロールの流れをchnageしないのはなぜですか? – naveen

答えて

1

うん... もちろんあなたはそれぞれ同じイメージを取得しています。あなたはまったく同じURLを渡しています。両方に同じSession値を使用しています。

あなたのコードでは、同じ応答内で2つの画像を送信しようとしているようです。それは、最初はこの問題に関連しているかどうかわからないという点では全く意味がありません。

QueryStringの値に基づいてイメージを異なるものにする必要があります。あなたのハンドラはあなたがそうしない限り違いを知らせません。

+0

彼は彼のdatarowから別の列を使用していることを確認してください。 – naveen

1

このようにコードを変更する必要があります。 Page_Load

ProcessRequest内部 whileループ内
imgPhoto.ImageUrl = "Image.ashx?ImageType=photo&EmpBadge=" & Session("EmpBadge") 
imgSign.ImageUrl = "Image.ashx?ImageType=signature&EmpBadge=" & Session("EmpBadge") 

、このような場合、他の場所のANで

If drPhoto.HasRows Then 
    While drPhoto.Read() 
     If context.Request.QueryString("ImageType") = "photo" Then 
      context.Response.ContentType = "image/" & drPhoto("PhotoType") 
      context.Response.BinaryWrite(DirectCast(drPhoto("Photo"), Byte())) 
     Else 
      context.Response.ContentType = "image/" & drPhoto("Signaturetype") 
      context.Response.BinaryWrite(DirectCast(drPhoto("Signature"), Byte())) 
     End If 
    End While 
End If 
関連する問題