开发者

Displaying image on a separate page

I have a image datatype which on click of a linkbutton needs to be displayed on a seperate page

aspx page
    detail view: 
    <asp:TemplateField HeaderText="Evidence (if any)">
                  <ItemTemplate>
开发者_StackOverflow社区                    <asp:LinkButton ID="lbEvidence" runat="server"
                     Text='<%# DataBinder.Eval(Container.DataItem, "Evidence").ToString()    == String.Empty ? "None" : DataBinder.Eval(Container.DataItem, "Evidence")%>'
                            CommandName="Select" CommandArgument = '<%# DataBinder.Eval(Container.DataItem, "Complaint_Id") %>'> </asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>

ImageHandler.ashx

    <%@ WebHandler Language="C#" Class="FMMadminModule.imageHandler" %>

using System;
using System.Web;
using System.Data;
using System.Web.SessionState;

    namespace FMMadminModule
    {
    public class imageHandler : IHttpHandler, IReadOnlySessionState
    {
    DataTable dt;
    int key;
    byte[] imageOut;
    public void ProcessRequest(HttpContext context)
    {            
        HttpResponse response = context.Response;
        HttpRequest request = context.Request;
        context.Response.ContentType = "image/jpeg";
        response.BufferOutput = false;
        // get the key, the index into the DataTable
        key = Convert.ToInt32(request.QueryString["Complaint_ID"]);           
        // Prepare the datatable to hold the SNo key and the jpeg image, which will be written out 
        dt = new DataTable();
        dt = (DataTable)context.Session["dt"];
        if (!dt.Rows[key]["Evidence"].Equals(null))
        {
            imageOut = (byte[])dt.Rows[key]["Evidence"];
            response.OutputStream.Write(imageOut, 0, imageOut.Length);
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
}

How would I display the image on a separate page? This is how aspx.cs looks like

 protected void dvResolveComplaint_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            DetailsViewRow row = dvResolveComplaint.Rows[5];
            //String RowId = (e.NewSelectedIndex).ToString(); 
            Type csType = this.GetType();
            String strScript = "<script> ";
            strScript += @"var newWindow = window.open('imageHandler.ashx?Complaint_ID=" + e.CommandArgument + @"', 'Evidence', ' height=450, center:yes, width=600, status=no, resizable= yes, menubar=no, toolbar=no, location=yes, scrollbars=no, status=no')";
            strScript += "</script>";
            ClientScript.RegisterClientScriptBlock(csType, "ViewEvidence", strScript);
            dvResolveComplaint.Attributes.Add("OnClick", strScript);
        }
    }


this is way overcomplicated. You don't need the linkbutton at all, just write an anchor-wrapped image in your item template and call it a day, e.g.:

<a href='url_to_your_handler' target="_blank"><img src='url_to_your_handler' alt='complaint image' /></a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜