http://www.dotnetspider.com/resources/40858-Preview-Image-before-uploading-using.aspx if i write the below code in side my master page its not working. MY aspx page <pre><%@ Page Language="C#" AutoEventWireup="true" CodeFile="image3.aspx.cs" Inherits="image3" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function uploadStarted() { $get("imgDisplay").style.display = "none"; } function uploadComplete(sender, args) { var imgDisplay = $get("imgDisplay"); imgDisplay.src = "images/loading.jpg"; imgDisplay.style.cssText = ""; var img = new Image(); img.onload = function () { imgDisplay.style.cssText = "height:100px;width:100px"; imgDisplay.src = img.src; }; img.src = "<%=ResolveUrl(UploadFolderPath) %>" + args.get_fileName(); } function clearcontents() { var AsyncFileUpload = $get("<%=AsyncFileUpload1.ClientID%>"); var txts = AsyncFileUpload.getElementsByTagName("input"); for (var i = 0; i < txts.length; i++) { if (txts[i].type == "text") { txts[i].value = ""; txts[i].style.backgroundColor = "white"; } } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:AsyncFileUpload OnClientUploadComplete="uploadComplete" runat="server" ID="AsyncFileUpload1" ThrobberID="imgLoader" OnUploadedComplete="FileUploadComplete" OnClientUploadStarted="uploadStarted" /> <asp:Image ID="imgLoader" runat="server" ImageUrl="images/loading.jpg" /><br /><br /> <img id = "imgDisplay" alt="" src="" style = "display:none"/> <br /> <br /> <asp:LinkButton ID="previewdel" runat="server" Text="Delete" onclick="previewdel_Click"/> </div> </form> </body> </html>
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class image3 : System.Web.UI.Page { protected string UploadFolderPath = "~/Uploads/"; protected void Page_Load(object sender, EventArgs e) { } protected void FileUploadComplete(object sender, EventArgs e) { string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName); AsyncFileUpload1.SaveAs(Server.MapPath(this.UploadFolderPath) + filename); } protected void previewdel_Click(object sender, EventArgs e) { clearcontents(sender as Control); } private void clearcontents(Control control) { for (var i = 0; i < Session.Keys.Count; i++) { if (Session.Keys[i].Contains(control.ClientID)) { Session.Remove(Session.Keys[i]); break; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)