尝试在基于employeeid的图像控件中从数据库中检索和显示图像...我采用了一个httphandler,其中包含以下内容:
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
Dim employeeId As Integer
If (Not (context.Request.QueryString("employeeId")) Is Nothing) Then
employeeId = Convert.ToInt32(context.Request.QueryString("employeeId"))
Else
Throw New ArgumentException("No parameter specified")
End If
Dim imageData() As Byte = {}
' get the image data from the database using the employeeId Querystring
context.Response.ContentType = "image/jpeg"
' You can retrieve this also from the database
context.Response.BinaryWrite(imageData)
End Sub
Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
bind()
GridView1.Visible = "True"
ProcessRequest(Context)
End Sub
错误:The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
我哪里出错了?我需要进行哪些更改?
这是窗体上的图像控件:
<asp:Image ID="Image1" runat="server" imageUrl="HttpHandler.ashx?employeeId=5"/>
@Stefano Altieri:
这是在 Employee.aspx 上
Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
bind()
GridView1.Visible = "True"
Image1.ImageUrl = "~/HttpHandler.ashx?EmployeeID='" & EmailIDTextBox.Text & "'"
End Sub
这是在 HttpHandler.ashx
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World!")
Dim employeeId As Integer
If (Not (context.Request.QueryString("employeeId")) Is Nothing) Then
employeeId = Convert.ToInt32(context.Request.QueryString("employeeId"))
Else
Throw New ArgumentException("No parameter specified")
End If
Dim imageData() As Byte = {}
' get the image data from the database using the employeeId Querystring
context.Response.ContentType = "image/jpeg"
' You can retrieve this also from the database
context.Response.BinaryWrite(imageData)
End Sub