Hi, I'm having problems with using the AjaxFileUpload control.
VS2008 - .NET framework 3.5. Placed the AjaxFileUpload control, and changed the aspx and code behind like given below. This is what happens after running:
1) Select -> file, the filename is correct displayed
The filename (pending)
2) Upload -> after clicking the upload button the filename textbox get red colored and is showing
The filename (errror)
The thing I don't understand is why the UploadComplete event (in code behind file) never get hit. Direct after clicking the upload button the message "error" is shown in red. What can be the cause of this, it looks al so basic, but it is causing me headaches.
Any help is appreciated.
Coen
-----------------------------------------------------------------------------------------------------------------
*** Code (aspx) ***
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ 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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:Label runat="server" ID="myThrobber" Style="display: none;"><img alt="" src="Images/ajax-loader.gif"/></asp:Label>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10"/>
</div>
</form>
</body>
</html>
*** Code (C#) ***
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = "~/upload/" + e.FileName;
AjaxFileUpload1.SaveAs(filePath);
}
}
-----------------------------------------------------------------------------------------------------------------
Comments: ***** CODE (aspx) *** ``` <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ 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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <br /> <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" onuploadcomplete="AjaxFileUpload1_UploadComplete" Width="700px" /> </div> </form> </body> </html> ``` **** Code (C#) **** ``` using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { String path = Server.MapPath("~/UploadedImages/") + e.FileName; AjaxFileUpload1.SaveAs(path); } } ```
VS2008 - .NET framework 3.5. Placed the AjaxFileUpload control, and changed the aspx and code behind like given below. This is what happens after running:
1) Select -> file, the filename is correct displayed
The filename (pending)
2) Upload -> after clicking the upload button the filename textbox get red colored and is showing
The filename (errror)
The thing I don't understand is why the UploadComplete event (in code behind file) never get hit. Direct after clicking the upload button the message "error" is shown in red. What can be the cause of this, it looks al so basic, but it is causing me headaches.
Any help is appreciated.
Coen
-----------------------------------------------------------------------------------------------------------------
*** Code (aspx) ***
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ 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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:Label runat="server" ID="myThrobber" Style="display: none;"><img alt="" src="Images/ajax-loader.gif"/></asp:Label>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10"/>
</div>
</form>
</body>
</html>
*** Code (C#) ***
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = "~/upload/" + e.FileName;
AjaxFileUpload1.SaveAs(filePath);
}
}
-----------------------------------------------------------------------------------------------------------------
Comments: ***** CODE (aspx) *** ``` <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ 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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <br /> <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" onuploadcomplete="AjaxFileUpload1_UploadComplete" Width="700px" /> </div> </form> </body> </html> ``` **** Code (C#) **** ``` using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { String path = Server.MapPath("~/UploadedImages/") + e.FileName; AjaxFileUpload1.SaveAs(path); } } ```