Triyng來檢索和顯示圖像從數據庫... 我已在其中我有此一個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阿爾鐵:
這是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
你知道哪裏有異常被拋出行? – 2013-03-04 09:42:03
當我打電話ProcessRequest(即,當它應該去httphandler(.ashx頁面)) – adityawho 2013-03-04 09:44:05
另外...我有點困惑...這是一個頁面或HTTP處理程序?它不能都是..你必須在一個單獨的ashx文件中實現http處理程序 – 2013-03-04 09:44:19