image preview working in firefox but its not working in ie9

Posted by reddysankark-13471 under ASP.NET on 10/19/2012 | Points: 10 | Views : 1198 | Status : [Member] | Replies : 0
hi,
aspx coding
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function getRandomNumber() {
var randomnumber = Math.random(10000);
return randomnumber;
}

function OnClientAsyncFileUploadComplete(sender, args) {
var handlerPage = '<%= Page.ResolveClientUrl("~/Handler.ashx")%>';
var queryString = '?randomno=' + getRandomNumber();
var src = handlerPage + queryString;
var clientId = '<%=previewImage.ClientID %>';
document.getElementById(clientId).setAttribute("src", src);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>


<asp:AsyncFileUpload ID="asyncFileUpload" runat="server"
OnClientUploadComplete="OnClientAsyncFileUploadComplete"
OnUploadedComplete="OnAsyncFileUploadComplete" />
<asp:Image runat="server" ID="previewImage" Height="200" Width="200" />
</form>
aspx.cs
public static readonly string STORED_IMAGE = "SessionImage";
protected void OnAsyncFileUploadComplete(object sender, AsyncFileUploadEventArgs e)
{
if (asyncFileUpload.PostedFile != null)
{
HttpPostedFile file=asyncFileUpload.PostedFile;
byte[] data = ReadFile(file);
Session[STORED_IMAGE] = data;
}
}
private byte[] ReadFile(HttpPostedFile file)
{
byte[] data = new Byte[file.ContentLength];
file.InputStream.Read(data, 0, file.ContentLength);
return data;
}
handler
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();

if (context.Request.QueryString.Count != 0)
{
var storedImage = context.Session[_Default.STORED_IMAGE] as byte[];
if (storedImage != null)
{
Image image = GetImage(storedImage);
if (image != null)
{
context.Response.ContentType = "image/jpeg";
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
}
}

private Image GetImage(byte[] storedImage)
{
var stream = new MemoryStream(storedImage);
return Image.FromStream(stream);
}

public bool IsReusable
{
get { return false; }
}

sankarreddy


Responses

(No response found.)

Login to post response