What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2822 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > image preview working in firefox but its not working in ie9 ...
Reddysankark@Yahoo.Com

image preview working in firefox but its not working in ie9

Replies: 0 | Posted by: Reddysankark@Yahoo.Com on 10/19/2012 | Category: ASP.NET Forums | Views: 338 | Status: [Member] | Points: 10  


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


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

  No reply found.


Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 9:31:43 PM