Thanks. I created the Handler and put the original codes inside it.
I have these codes to call the handler in the original aspx page.
...
<asp:Image ID="img"
imageurl='<%# Eval("user_abbr","Handler1.ashx?user_abbr={0}") %>'
runat="server" />
...
I have these in web.config
...
<system.web>
<urlMappings enabled="true">
<add url="~/Default.aspx" mappedUrl="~/Handler1.ashx"/>
</urlMappings>
...
Here is the handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Edit_user_rec
{
/// <summary>
/// Summary description for Handler1
/// </summary>
public class Handler1 : IHttpHandler
{
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 23, 2012 10:46 PM|LINK
Thanks all.
Oned,
You are correct. I have only one aspx page in this project. Is there no way to show the image inside the same aspx page, which is the main one?
HuaMin Chen
oned_gk
All-Star
31247 Points
6384 Posts
Re: Nothing is shown
Nov 23, 2012 11:59 PM|LINK
ASPX PAGE (gridview here)
ASHX PAGE
ProcessRequest and give the image for id 123, so your code here
rtpHarry
All-Star
56620 Points
8958 Posts
Re: Nothing is shown
Nov 24, 2012 08:20 AM|LINK
You dont have a file called GetImage.ashx?
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 26, 2012 12:55 AM|LINK
Thanks all.
Harry,
You're right. That page is not in my project and I have only one aspx file in the project.
Oned/Harry,
How to show that on the only aspx page in the project?
HuaMin Chen
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 27, 2012 02:06 AM|LINK
Any advice?
HuaMin Chen
oned_gk
All-Star
31247 Points
6384 Posts
Re: Nothing is shown
Nov 27, 2012 02:45 AM|LINK
You can save all images in gv rows to a folder, then set the imageurl to the images. But i think this is bad solution and hardway.
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 27, 2012 03:10 AM|LINK
How to adjust the above codes which is retrieving one image from the table? Do I need 2 aspx pages in this project?
HuaMin Chen
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 28, 2012 03:12 AM|LINK
Any more help?
HuaMin Chen
oned_gk
All-Star
31247 Points
6384 Posts
Re: Nothing is shown
Nov 28, 2012 06:36 AM|LINK
I think you already have the code.
Create Imagehandler.ashx file and move your code to the ashx file.
try to test image in address bar : http://..../Imagehandler.ashx?userid=123
if the image diplayed then use the url above as imageurl in aspx page
wmec
Contributor
6219 Points
3217 Posts
Re: Nothing is shown
Nov 29, 2012 02:21 AM|LINK
Thanks. I created the Handler and put the original codes inside it.
I have these codes to call the handler in the original aspx page.
...
<asp:Image ID="img"
imageurl='<%# Eval("user_abbr","Handler1.ashx?user_abbr={0}") %>'
runat="server" />
...
I have these in web.config
...
<system.web>
<urlMappings enabled="true">
<add url="~/Default.aspx" mappedUrl="~/Handler1.ashx"/>
</urlMappings>
...
Here is the handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Edit_user_rec
{
/// <summary>
/// Summary description for Handler1
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
System.Data.SqlClient.SqlDataReader rdr = null;
System.Data.SqlClient.SqlConnection conn = null;
System.Data.SqlClient.SqlCommand selcmd = null;
try
{
conn = new System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings
["Mssqlconn2"].ConnectionString);
string user_abbr = context.Request.QueryString["user_abbr"];
string strParameter = "";
if (HttpContext.Current.Request.QueryString["user_abbr"] != null)
{
strParameter = HttpContext.Current.Request.QueryString["user_abbr"];
}
string strQuery = "select photo_file from user_master where user_abbr='" + strParameter + "'";
selcmd = new System.Data.SqlClient.SqlCommand(strQuery, conn);
conn.Open();
rdr = selcmd.ExecuteReader();
if (rdr.Read())
{
string flnm = "fl1.jpg";
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + flnm);
context.Response.BinaryWrite((byte[])rdr["photo_file"]);
context.Response.Flush();
}
if (rdr != null)
rdr.Close();
}
finally
{
if (conn != null)
conn.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
but once the project has been started, I've got empty page again.
HuaMin Chen