The first thing I'm noticing is that you don't have any triggers defined on your update panel.
Below the "ContentTemplate" tag, add a "Triggers" tag like below. You might also want to modify the UpdatePanel's attributes at indicated below, this will provide greater control over when the update panel does it's server-request and improve performance
by preventing it from updating when it doesn't need to. (I am assuming, of course, that your page is a bit more complex than what is listed here)
Another thing to be aware of is that I have seen many post (and had some issues personally) with the AsyncFileUpload control not triggering the "UploadComplete" event on the server. You might want to put a breakpoint in and make sure that this postback in occurring.
If it's not, you can get around this problem by using the "OnClientUploadComplete" property and pointing it at some javascript function that will "fake" a postback.
Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles fileUpload.UploadedComplete
If Me.fileUpload.HasFile = True Then
Dim folder As String = "57aa12cde175487a975d3499cb3c4bd9"
Me.fileUpload.SaveAs(Server.MapPath("Uploads/") & folder & "/" & Me.fileUpload.PostedFile.FileName)
Me.Label1.Text = "uploaded"
End If
End Sub
Protected Sub btnUploadcompleted_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUploadcompleted.Click
Me.UpdatePanel1.Update()
End Sub
ProgrammerOn...
Member
13 Points
80 Posts
asyncfileupload
Oct 01, 2010 09:05 PM|LINK
I am using an asynfileupload to save data to a database. After the data is saved into the database . I need to update an updatepanel .
<head runat="server">
<title></title>
<script type ="text/javascript" >
function UploadComplete(sender, args) {
__doPostBack('UpdatePanel1', '');
}
</script>
</head>
<body>
<form id="form1" runat="server"> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
</div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode ="Always" runat="server">
<ContentTemplate >
<asp:Label ID="Label1" runat="server" Text ="1" Visible ="true" ></asp:Label></ContentTemplate>
</asp:UpdatePanel>
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
OnClientUploadComplete="UploadComplete" onuploadedcomplete="AsyncFileUpload1_UploadedComplete"
/>
</form>
</body>
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string savePath = MapPath("~/ExcelUpload/" + "1.xls");
AsyncFileUpload1.SaveAs(savePath);
UpdateDataBase();
Label1.Text = "saved";
}
As you can see the Label1.Text is modified in code behind but that is not reflected on the page. How can I do this?
TenshiNo
Member
8 Points
5 Posts
Re: asyncfileupload
Oct 01, 2010 11:18 PM|LINK
The first thing I'm noticing is that you don't have any triggers defined on your update panel.
Below the "ContentTemplate" tag, add a "Triggers" tag like below. You might also want to modify the UpdatePanel's attributes at indicated below, this will provide greater control over when the update panel does it's server-request and improve performance by preventing it from updating when it doesn't need to. (I am assuming, of course, that your page is a bit more complex than what is listed here)
Another thing to be aware of is that I have seen many post (and had some issues personally) with the AsyncFileUpload control not triggering the "UploadComplete" event on the server. You might want to put a breakpoint in and make sure that this postback in occurring.
If it's not, you can get around this problem by using the "OnClientUploadComplete" property and pointing it at some javascript function that will "fake" a postback.
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: asyncfileupload
Oct 05, 2010 08:34 AM|LINK
Hi,
Please change your code as below. I have tested, and it is running normal.
<head runat="server"> <title></title> <script type ="text/javascript" > function UploadComplete(sender, args) { __doPostBack('UP_Btn', ''); } </script> </head> <body> <form id="form1" runat="server"> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <div> </div> <asp:Button ID="UP_Btn" runat="server" Text="Updatepanel_Trigger" onclick="UP_Btn_Click" style="display:none" /> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate > <asp:Label ID="Label1" runat="server" Text ="1" Visible ="true" ></asp:Label></ContentTemplate> </asp:UpdatePanel> <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="UploadComplete" onuploadedcomplete="AsyncFileUpload1_UploadedComplete" /> </form> </body>protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { string savePath = MapPath("~/ExcelUpload/" + "1.xls"); AsyncFileUpload1.SaveAs(savePath); UpdateDataBase(); Label1.Text = "saved"; } protected void UP_Btn_Click(object sender, EventArgs e) { UpdatePanel1.Update(); }Feedback to us
Develop and promote your apps in Windows Store
said_tambal
Member
4 Points
13 Posts
Re: asyncfileupload
Oct 06, 2010 08:22 PM|LINK
hi
i tried your code, but now it runs twice into the "AsyncFileUpload1_UploadedComplete" Sub...
So my Image will be saved twice...
how can i prevent this?
thanx! :)
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: asyncfileupload
Oct 07, 2010 02:08 AM|LINK
Hi,
The "AsyncFileUpload1_UploadedComplete" Sub not run twice. Please test again. I have tested on my side. Everything is OK.
Feedback to us
Develop and promote your apps in Windows Store
said_tambal
Member
4 Points
13 Posts
Re: asyncfileupload
Oct 07, 2010 04:55 PM|LINK
ok ill show you my code :)
<%@ Page Title="" Language="VB" MasterPageFile="~/Master.master" AutoEventWireup="false" CodeFile="addImages.aspx.vb" Inherits="addImages" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <link rel="stylesheet" type="text/css" href="App_Themes/default/addImages.css" /> <script type="text/javascript"> function UploadComplete(sender, args) { __doPostBack("<%=btnUploadcompleted.ClientID %>", ''); } </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:AsyncFileUpload ID="fileUpload" runat="server" CompleteBackColor="#99FF99" UploadingBackColor="#66CCFF" ErrorBackColor="#FF3300" ThrobberID="imgUploadPrograss" onclientuploadcomplete="UploadComplete" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <asp:Button ID="btnUploadcompleted" runat="server" Text="UpdatePanelUpdater" /> <asp:Image ID="imgUploadPrograss" runat="server" ImageUrl="~/App_Themes/default/images/ajax-loader.gif" /> </asp:Content>Protected Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles fileUpload.UploadedComplete If Me.fileUpload.HasFile = True Then Dim folder As String = "57aa12cde175487a975d3499cb3c4bd9" Me.fileUpload.SaveAs(Server.MapPath("Uploads/") & folder & "/" & Me.fileUpload.PostedFile.FileName) Me.Label1.Text = "uploaded" End If End Sub Protected Sub btnUploadcompleted_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUploadcompleted.Click Me.UpdatePanel1.Update() End Sub