displaying image (from database) in an image control
<p>Triyng to retrieve and display image from database in an image control based on employeeid...
I have taken an httphandler in which i have this:</p>

<pre class="lang-vb prettyprint-override"><code>  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
</code></pre>

<p>Error: <code>The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.</code>
Where am I going wrong? What all changes do i need to make?</p>

<p>This is the image control on the form:</p>

<pre><code>&lt;asp:Image ID="Image1" runat="server" imageUrl="HttpHandler.ashx?employeeId=5"/&gt;
</code></pre>

<p>@Stefano Altieri:</p>

<p>This is on Employee.aspx</p>

<pre><code>Protected Sub DisplayButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DisplayButton.Click
    bind()
    GridView1.Visible = "True"
    Image1.ImageUrl = "~/HttpHandler.ashx?EmployeeID='" &amp; EmailIDTextBox.Text &amp; "'"
End Sub
</code></pre>

<p>and this is on HttpHandler.ashx</p>

<pre><code>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
</code></pre>
