okey now i have solved
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="3433"></asp:TextBox>
<div style="padding: 40px">
<asp:FileUpload ID="FileUpload1" runat="server" />
<table class="rounded_corners" id="attachedfiles">
</table>
</div>
</div>
<script type="text/javascript">
$(window).load(
function () {
$("#<%=FileUpload1.ClientID %>").fileUpload({
'uploader': 'scripts/uploader.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Handler.ashx',
'folder': 'uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
<%-- 'formData': { "id2": "<%=TextBox1.Text %>" },--%>
'scriptData': { "id2": "<%=TextBox1.Text %>" },
'multi': true,
'auto': true,
'onComplete': function (event, ID, file, response, data) {
$("#attachedfiles").append("<tr><td>" + file.name + "</td><td><img src=" + file.filePath + " height='100' width='100' /></td><td><a href = 'javascript:;'>[x]</a></td></tr>");
}
});
}
);
</script>
<script type="text/javascript">
$("#attachedfiles a").live("click", function () {
var row = $(this).closest("tr");
var fileName = $("td", row).eq(0).html();
$.ajax({
type: "POST",
url: "Default3.aspx/RemoveFile",
data: '{fileName: "' + fileName + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () { },
failure: function (response) {
alert(response.d);
}
});
row.remove();
});
</script>
handler code
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//string id2 = context.Request.Form[1];
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
string fileId = context.Request.QueryString["id2"];
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string savepath = "";
string tempPath = "";
tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath = context.Server.MapPath(tempPath);
string filename = postedFile.FileName;
if (!System.IO.Directory.Exists(savepath))
System.IO.Directory.CreateDirectory(savepath);
postedFile.SaveAs(savepath + @"\" + filename);
context.Response.Write(tempPath + "/" + filename);
context.Response.StatusCode = 200;
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr))
{
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("INSERT INTO tbl_image(FileName,FilePath,id2) VALUES(@FileName,@FilePath,@id2)", con))
{
cmd.Parameters.AddWithValue("@FileName", filename);
cmd.Parameters.AddWithValue("@FilePath", tempPath + "/" + filename);
cmd.Parameters.AddWithValue("@id2", fileId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}