User1734617369 posted
Hi,
The problem is that the event OnUploadedComplete is not part of the standard page lifecycle so even if you assign a datasource to the DropDownList in that event this will not update the DropDownList since it won't be rendered again, on way of doing
it is like in this example, tha page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function AddFileNameToList(sender, args) {
<%=ClientScript.GetPostBackEventReference(UP1, "" )%>;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="AddFileNameToList" OnUploadedComplete="AsyncFileUpload1_OnUploadedComplete" />
<asp:UpdatePanel runat="server" ID="UP1">
<ContentTemplate>
<asp:DropDownList runat="server" ID="FileList" AutoPostBack="True" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
and the code:
using System.Collections.Generic;
using AjaxControlToolkit;
using System;
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
FileList.Items.Clear();
FileList.DataSource = Session["SheetNames"] != null
? (List<string>) Session["SheetNames"]
: new List<string>();
FileList.DataBind();
}
}
protected void AsyncFileUpload1_OnUploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
if (Session["SheetNames"] != null)
{
((List<string>)Session["SheetNames"]).Add(e.FileName);
}
else
{
Session["SheetNames"] = new List<string> {e.FileName};
}
}
}
}
in your case you can assign the shhet names to the session variable and use that instead. This may not be the most elegant solution but should work if you adds some error checking and such.
Best regards
Johan