I have verified your code. There is no issue with the code.
Remove below line from Image handler.
<%@ WebHandler Language="C#" CodeBehind="ImageHandler.ashx.cs" Class="OCMS.ImageHandler" %>
This line required when you have empty website not in web application.
HTML
<body bgcolor="#F0F8FF">
<form id="form1" runat="server">
<table width="100%" height="30" border="1" cellpadding="1" cellspacing="1">
<tr bgcolor="#3090C7">
<td class="auto-style4"> <img src="image/m1.png" class="auto-style1" />
</td>
<td colspan="5" class="auto-style3">
<u><span class="auto-style8">
<font color="white" class="auto-style9"><strong>COMPLAINT MANAGEMENT SYSTEM</strong></font></span></u>
<marquee attribute_name="attribute_value">
For any assistance please contact 3126 or mail to munplit@ntpc.co.in
</marquee>
</td>
<td class="auto-style3">
<script type="text/javascript">
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var day1 = currentTime.getDay()
if (day1 == 1)
document.write("Monday")
else if (day1 == 2)
document.write("Tuesday")
else if (day1 == 3)
document.write("Wednesday")
else if (day1 == 4)
document.write("Thursday")
else if (day1 == 5)
document.write("Friday")
else if (day1 == 6)
document.write("Saturday")
else if (day1 == 7)
document.write("Sunday"
)
document.write(" " + day + "/" + month + "/" + year)
</script>
<br />
<strong>
<br />
Emp. Id:
<asp:Label ID="lblName" runat="server" Text="Label"></asp:Label>
<br />
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CssClass="auto-style7">BACK</asp:LinkButton>
</strong>
</td>
</tr>
</table>
<table border="1">
<tr>
<td>
<h4>COMPLAINT CATEGORY</h4>
<select name="cat" size="1" onchange="redirect(this.options.selectedIndex);SetMessage();">
<option value="0" selected="selected">Select a category</option>
<option value=""></option>
<option value="--">-----------------------------------------</option>
<option value="PC -">PC</option>
<option value="Printer -">Printer</option>
<option value="Phone">Phone</option>
<option value="Scanner -">Scanner</option>
<option value="UPS -">UPS</option>
<option value="Network -">Network</option>
<option value="Application -">Application</option>
<option value="Software -">Software</option>
<option value="General -">General</option>
<option value="ERP -">ERP</option>
<option value="Mail -">Mail</option>
</select>
</td>
<td>
<div name="dvPrinter" style="display: none;">
<h4>PRINTER TYPE:</h4>
<select name="printer" size="1" onchange="SetMessage()">
<option value="0" selected="selected">Select a category</option>
<option value=""></option>
<option value="--">-----------------------------------------</option>
<option value="Personal -">Personal</option>
<option value="Common -">Common</option>
</select>
</div>
</td>
<td>
<h4>TYPE</h4>
<select name="type" size="1" onchange="SetMessage()"></select>
</td>
<td>
<div name="Location">
<h4>LOCATION:</h4>
<select name="Location" size="1" onchange="SetMessage()">
<option value="0" selected="selected">Select a category</option>
<option value=""></option>
<option value="--">-----------------------------------------</option>
<option value="H-type">H-type</option>
<option value="DM Plant -">DM Plant</option>
<option value="Service Building -">Service Building </option>
<option value="MGR">MGR</option>
<option value="CHP">CHP</option>
<option value="CCD Township">CCD Township</option>
<option value="Hospital Township">Hospital Township</option>
<option value="Switchyard">Switchyard</option>
<option value="Kanta">Kanta</option>
<option value="Main Gate Plant">Main Gate Plant</option>
<option value="AHP">AHP</option>
<option value="UPL Office">UPL Office</option>
<option value="CCR">CCR</option>
<option value="Fire Station">Fire Station</option>
<option value="Guest House">Guest House</option>
<option value="Township">Township</option>
<option value="Safety Park">Safety Park</option>
</select>
</div>
</td>
<td>
<h4>Image File:</h4>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<script type="text/javascript">
var groups = document.forms.form1.cat.length
var group = new Array(groups)
for (i = 0; i < groups; i++)
group[i] = new Array()
group[3][0] = new Option("CD/DVD/Pen--Drive/Writer not working", "CD/DVD/Pen--Drive/Writer problem")
group[3][1] = new Option("Monitor problem", "Monitor problem")
group[3][2] = new Option("Keyboard Problem", "Keyboard Problem")
group[3][3] = new Option("Mouse Problem", "Mouse Problem")
group[3][4] = new Option("PC Not Booting", "Booting Problem")
group[3][5] = new Option("PC Running slow", "PC Running slow")
group[3][6] = new Option("PC Connection Problem", "PC Connection Problem")
group[3][7] = new Option("PC Shifting", "PC Connection Problem")
group[4][0] = new Option("Paper Jam Problem", "Paper Jam Problem")
group[4][1] = new Option("Printer not Installed/Issue", "Installation/Driver Issue")
group[4][2] = new Option("Garbage/Junk Printing Problem", "Garbage Printing Problem")
group[4][3] = new Option("Red LED/Error Light Blinking ", "Printer Error(Red LED)")
group[5][0] = new Option("Intercom Dead", "Intercom Dead")
group[5][1] = new Option("Landline Dead", "Landline Dead")
group[5][2] = new Option("Phone Set Problem", "Phone Set Problem")
group[5][3] = new Option("Line shifting", "Line shifting")
group[6][0] = new Option("Device Connectivity Error", "Connectivity Problem")
group[6][1] = new Option("Driver Installation/Issue", "Driver problem")
group[6][2] = new Option("Not scanning Properly", "Function Problem")
group[7][0] = new Option("Cannot Start", "On/Off Problem")
group[7][1] = new Option("Not giving Backup", "Backup Problem")
group[7][2] = new Option("DG Set Switching Problem", "DG Set Switch problem")
group[7][3] = new Option("eProcurement System")
group[8][0] = new Option("Internet not working", "Internet Problem")
group[8][1] = new Option("Intranet not opening", "Intranet problem")
group[8][2] = new Option("Links/Peoplesoft does not open", "Links Problem")
group[8][3] = new Option("Internet/Intranet Slow", "Intranet/Internet slow speed Problem")
group[9][0] = new Option("Complaint Management Sys. not working", "IT Assets sys. Problem")
group[9][1] = new Option("E-Workspace not working", "E-Workspace Appl. problem")
group[9][2] = new Option("EIS not working", "EIS Appl. problem")
group[9][3] = new Option("File Tracking System not working", "FTS Appl. problem")
group[9][4] = new Option("OS daily report not working", "OS-Daily report Appl. problem")
group[9][5] = new Option("RED(N)'s Desk not working", "RED(N)'s Appl. Problem")
group[9][6] = new Option("GDAMS application Problem", "GDAMS Problem")
group[9][7] = new Option("Application USERID/PASSWORD Problem", "Userid/Password Problem")
group[9][8] = new Option("Application Data not updated", "Appl. Data Problem")
group[9][9] = new Option("MS Team")
group[9][10] = new Option("MS Office")
group[9][11] = new Option("Adobe")
group[9][12] = new Option("Java")
group[9][13] = new Option("Finmat")
group[9][14] = new Option("eProcurement System")
group[10][0] = new Option("Acorbat Reader Installation/Error", "Acrobat Issue")
group[10][1] = new Option("Antivirus Patch/Virus Issue", "Antivirus Issue")
group[10][2] = new Option("CD Writer S/W Installation/Error", "CD Writer S/W Issue")
group[10][3] = new Option("Hindi Fonts Installation", "Hindi Fonts Issue")
group[10][4] = new Option("MS Office Installation/Error", "MS Office Issue")
group[10][5] = new Option("PDF Writer", "PDF Writer Issue")
group[10][6] = new Option("Winzip/Winrar Installation/Issue", "Winzip/Rar Issue")
group[10][7] = new Option("Installation of a software", "Some software to be loaded")
group[11][0] = new Option("Intranet not updated", "Intranet Update Issue")
group[11][1] = new Option("Lodged Complaint still pending", "Complaint Handling problem")
group[12][0] = new Option("ESS ID Locked", "ESS ID Locked")
group[12][1] = new Option("SAP - R/3 ID Locked", "SAP R/3 ID Locked")
group[12][2] = new Option("ESS password forgetton", "ESS Password forgetton")
group[12][3] = new Option("SAP password forgetton", "SAP - R/3 Password forgetton")
group[12][4] = new Option("ESS Page not displayed properly", "ESS Page not displayed properly")
group[12][5] = new Option("ESS/SAP not installed", "ESS/SAP not installed")
group[13][0] = new Option("Cant open mail in Browser", "Browser Mail Problem")
group[13][1] = new Option("Cant open Lotus Notes", "Lotus Notes Problem")
group[13][2] = new Option("Internet Mail access problem", "Internet Mail access problem")
group[13][3] = new Option("Archiving Problem", "Archiving Problem")
group[13][4] = new Option("Certificate Expired", "Certificate Expired")
group[13][5] = new Option("Mobile mail configuration", "Mobile mail configuration")
var temp = document.forms.form1.type
function redirect(x) {
document.getElementsByName('dvPrinter')[0].style.display = "none";
if (document.forms.form1.cat[x].text == 'Printer') {
document.getElementsByName('dvPrinter')[0].style.display = "block";
}
for (m = temp.options.length - 1; m > 0; m--)
temp.options[m] = null
i = 0;
temp.options[i] = new Option("", "0")
for (i = 0; i < group[x].length; i++) {
temp.options[i + 1] = new Option(group[x][i].text, group[x][i].value)
}
temp.options[0].selected = true
}
function SetMessage() {
var str = document.forms.form1.str;
var cat = document.forms.form1.cat.value;
var printer = document.forms.form1.printer.value;
var type = document.forms.form1.type.value;
var location = document.forms.form1.Location.value;
var message = "";
if (cat != "0" && cat != '' && cat != '--') {
message += cat;
}
if (printer != "0" && printer != '' && printer != '--') {
message += ":- " + printer;
}
if (type != "0" && type != '' && type != '--') {
message += ":- " + type;
}
if (location != "0" && location != '' && location != '--') {
message += " :- " + location;
}
str.value = message;
}
</script>
<center>
<u><h3 align="left">IT COMPLAINT BOX :</h3></u>
</center>
<table width="700" height="168" border="3" bgcolor="#99CCCC" bordercolor="#000000">
<tr>
<td width="120" scope="col">
<center><b>COMPLAINT MESSAGE </b></center>
</td>
<td>
<asp:TextBox runat="server" ID="str" TextMode="Multiline" Columns="20" Name="S1" Rows="2" CssClass="auto-style10" Height="144px" Width="585px"></asp:TextBox>
</td>
</tr>
</table>
<center><asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></asp:Button></center>
</table>
<div align="center"><u><font color="#3333FF" size="+2" align="center"><b>YOUR'S COMPLAINT(S)</b></font></u></div>
<asp:GridView CssClass="Grid" ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Height="61px" Width="1087px">
<Columns>
<asp:BoundField HeaderText="COMP_ID" DataField="Id" />
<asp:BoundField HeaderText="EmpCode" DataField="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink
ID="MyLink" Target="_blank"
NavigateUrl='<%# Eval("id", "~/ImageHandler.ashx?Id={0}") %>'
runat="server">Image
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#str').focus(function () {
$(this).val('');
});
});
</script>
</body>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblName.Text = " " + Request.QueryString["EmpId"] + "";
}
if (!Page.IsPostBack)
{
BindGrid();
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Index.aspx?EmpId=" + lblName.Text.Trim());
}
private void SaveImage()
{
if (FileUpload1.HasFile)
{
int imagefilelenth = FileUpload1.PostedFile.ContentLength;
byte[] imgarray = new byte[imagefilelenth];
HttpPostedFile image = FileUpload1.PostedFile;
image.InputStream.Read(imgarray, 0, imagefilelenth);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlCommand cmd = new SqlCommand("Insert into IT_comp_box (EmpCode, COMP_MESSAGE,Image) values (@lblName, @str,@Image)", con);
con.Open();
cmd.Parameters.AddWithValue("@lblName", SqlDbType.VarChar).Value = lblName.Text;
cmd.Parameters.AddWithValue("@str", SqlDbType.VarChar).Value = str.Text.ToString();
// cmd.Parameters.Add("@str", SqlDbType.VarChar).Value = str.Text.ToString();
cmd.Parameters.AddWithValue("@Image", SqlDbType.Image).Value = imgarray;
cmd.ExecuteNonQuery();
BindGrid();
}
}
public void BindGrid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT * FROM tblFiles WHERE ContentType = 'image/jpeg'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
SaveImage();
// ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('" + str.Value + "')", true);
}
Handler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
namespace OCMS
{
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string imageId = context.Request.QueryString["Id"].ToString();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlCommand cmd = new SqlCommand("select Data from tblFiles where id=" + imageId, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
byte[] bytes = (byte[])dr[0];
con.Close();
context.Response.BinaryWrite(bytes);
context.Response.ContentType = "image/jpg";
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}