在我的页面中,我试图显示两个具有相同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