Text Input from Drop Down list is ignored in Ajax Control Upload and takes default value all the time

StackOverflow https://stackoverflow.com/questions/22652577

Pergunta

My Web page has an ajax control upload event for uploading zip file and unzipping(zlib) the zip folder by creating a folder name based on the Drop down list input. The issues faced are the default value when my web page loads is CEESI and it is taken as the drop down list input every time. If any other option selected from the ajax upload drop down list it is not taking the selected input for creating the folder name and cannot unzip my file as the error says path does not exists. Upload and Unzip works only for default dropdownlist input i.e. c

My Aspx source

<asp:DropDownList ID="DropDownList1" runat="server" Font-Size="Smaller">
                                <asp:ListItem>c</asp:ListItem>
                                <asp:ListItem>n</asp:ListItem>
                                <asp:ListItem>h</asp:ListItem>
                                <asp:ListItem>f</asp:ListItem>
                                <asp:ListItem>ce</asp:ListItem>
                                <asp:ListItem>si</asp:ListItem>
                            </asp:DropDownList>

My C# Code (aspx.cs)

protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
  string path_with_file_name = null;
  try
     {
      _path = Server.MapPath("~/App_data" + "/" + get_user_data(1) + "/" + DropDownList1.Text +    "/"); 
      **//How to retrieve selected drop down list input for Ajax Upload** 
       bool isExists = System.IO.Directory.Exists(_path);
       if (!isExists)
       System.IO.Directory.CreateDirectory(_path);
       path_with_file_name = _path + e.FileName;
       AjaxFileUpload1.SaveAs(Path.Combine(_path, e.FileName));
     }
  catch (UnauthorizedAccessException Uae)
     {
       throw Uae;
     }
       UnZipper uz = new UnZipper();
       uz.Destination = _path;
       uz.IfFileExist = enIfFileExist.Overwrite;
       uz.ItemList.Add("*.*");
       uz.Recurse = true;
       uz.ZipFile = @path_with_file_name;
       uz.UnZip();
    }
Foi útil?

Solução

You can store the selected item text into session state and read it from there.

But first add the OnSelectedItemChanged event to your dropdownlist and set AutoPostBack=true.

This link solves your problem: http://forums.asp.net/post/5162366.aspx

Edit:

In case the user didn't change the dropdownlist value, you'll need to modify the UploadComplete method to the following:

 protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        String value;
        if(Session["Value"] != null)
        {
             value = Session["Value"].ToString();
        }
        else
        {
             value = DropDownList1.SelectedItem.Text;
        } 
        //rest of your code
    }

And you can set the default selected listitem in dropdownlist like this:

<asp:DropDownList ID="DropDownList1" runat="server" Font-Size="Smaller">
                                <asp:ListItem Selected="True" >CEESI</asp:ListItem>
                                <asp:ListItem>NEL</asp:ListItem>
                                <asp:ListItem>HORSOY</asp:ListItem>
                                <asp:ListItem>FLATOY</asp:ListItem>
                                <asp:ListItem>CEPRO</asp:ListItem>
                                <asp:ListItem>SINTEF</asp:ListItem>
                            </asp:DropDownList>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top