The initialization status of both FileUpload1 and btnUpload are not visible, now I click btnDisplay to make them visible and run ScriptManager1.RegisterPostBackControl, then select and upload file, but failed, why?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Among several solutions, you can try to implement file uploading method using AJAX and WebService technologies, here’s the instructions and sample codes for you to refer.
if we want to work with file upload controls inside of update panel, we need to set triggers for that.... because asynchronous post back wont support file uploads.... if we are going to use triggers in update panel, it same as post back ...... but we cannot
avoid this...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Subgurim.Controles;
and a folder to C:\temp\NewAsk
It now works, I am just a beginner but I tried the above and it works.
Probably just add Register Ajax tool kit <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> and it will work
mycwcgr
Participant
1646 Points
924 Posts
FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 12, 2008 09:54 AM|LINK
The initialization status of both FileUpload1 and btnUpload are not visible, now I click btnDisplay to make them visible and run ScriptManager1.RegisterPostBackControl, then select and upload file, but failed, why?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnDisplay" runat="server" OnClick="btnDisplay_Click" Text="DisplayUpload" /><br />
<asp:FileUpload ID="FileUpload1" runat="server" Visible="False" /><br />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" Visible="False" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
FileUpload1.Visible = true;
btnUpload.Visible = true;
ScriptManager1.RegisterPostBackControl(btnUpload);
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(@"C:\Temp\NewAsk\"+FileUpload1.FileName);
}
}
}
A1ien51
All-Star
29503 Points
5718 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 12, 2008 01:29 PM|LINK
The XMLHttpRequest object does not support uploading files.
Eric
mycwcgr
Participant
1646 Points
924 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 12, 2008 10:34 PM|LINK
Could you tell me how can upload file in Ajax?
Nai-Dong Jin...
All-Star
41630 Points
3558 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 18, 2008 05:31 AM|LINK
Hi,
Among several solutions, you can try to implement file uploading method using AJAX and WebService technologies, here’s the instructions and sample codes for you to refer.
http://www.codeproject.com/KB/aspnet/AJAXUpload.aspx
Thanks.
vasanth.kumar.d
Contributor
5324 Points
1041 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 18, 2008 07:41 AM|LINK
Hi,
if you want to use file upload control inside the update panel, then you need to set postback triggers for the update panel...
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnDisplay" runat="server" OnClick="btnDisplay_Click" Text="DisplayUpload" /><br />
<asp:FileUpload ID="FileUpload1" runat="server" Visible="False" /><br />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" Visible="False" />
</ContentTemplate>
</asp:UpdatePanel>
Software Engineer.
mycwcgr
Participant
1646 Points
924 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 18, 2008 12:20 PM|LINK
To vasanth.kumar.d,
Thanks, but you are not correct, the code below don't work yet!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnDisplay" runat="server" OnClick="btnDisplay_Click" Text="DisplayUpload" /><br />
<asp:FileUpload ID="FileUpload1" runat="server" Visible="False" /><br />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" Visible="False" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDisplay_Click(object sender, EventArgs e)
{
FileUpload1.Visible = true;
btnUpload.Visible = true;
//ScriptManager1.RegisterPostBackControl(btnUpload);
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(@"C:\Temp\NewAsk\" + FileUpload1.FileName);
}
}
}
vasanth.kumar.d
Contributor
5324 Points
1041 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 19, 2008 03:04 AM|LINK
Hi,
you need to add two triggers for this....
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
<asp:PostBackTrigger ControlID="btnDisplay" />
</Triggers>
Software Engineer.
NC01
All-Star
82559 Points
15430 Posts
MVP
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 19, 2008 03:53 PM|LINK
Why use AJAX or an AJAX enabled control, if you're going to force a PostBack anyways?
NC...
vasanth.kumar.d
Contributor
5324 Points
1041 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Feb 20, 2008 02:59 AM|LINK
Hi,
if we want to work with file upload controls inside of update panel, we need to set triggers for that.... because asynchronous post back wont support file uploads.... if we are going to use triggers in update panel, it same as post back ...... but we cannot avoid this...
Software Engineer.
donboulton
Member
47 Points
10 Posts
Re: FileUpload control don't work in Ajax even if I run ScriptManager1.RegisterPostBackControl ?
Mar 31, 2008 01:02 PM|LINK
Added ajax control toolkit
<%@ Register Assembly="FUA" Namespace="Subgurim.Controles" TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
and I added to code behind
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Subgurim.Controles;
and a folder to C:\temp\NewAsk
It now works, I am just a beginner but I tried the above and it works.
Probably just add Register Ajax tool kit <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> and it will work
Don