在我的頁面中,我試圖顯示兩個具有相同ID的圖像。爲此,我有兩個圖像控件(imgX,imgY)。要將圖像寫入圖像控件,我使用HttpHandler(ashx)。我們是否需要爲每個圖像創建一個HttpHandler(ashx)?
我的問題是,我得到了相同的圖像追加到兩個控件(IMGX,IMGY)
在頁面加載事件,這是我的代碼:
imgPhoto.ImageUrl = "Image.ashx?EmpBadge=" & Session("EmpBadge")
imgSign.ImageUrl = "Image.ashx?EmpBadge=" & Session("EmpBadge")
而且在ASHX:
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
謝謝。
爲什麼不傳遞像''imagetype = photo「'這樣的另一個查詢字符串,並且使用簡單的if-else方法來控制ProcessRequest的控制流? – naveen 2012-02-17 05:38:02