The Ajax Control Upload consistently defaults to the default value and disregards any text input selected from the drop-down list

On my website, I have implemented an ajax control upload event that allows users to upload a zip file and then unzip it using zlib. The folder name for unzipping is created based on the selection from a dropdown list. However, I am facing some issues where the default value "CEESI" is always selected when the page loads, causing the folder to be named incorrectly. Even if a different option is chosen from the dropdown list during the ajax upload, the selected input is not recognized for creating the folder name, resulting in an error stating that the path does not exist. The upload and unzip functionality only works for the default dropdown list input "c".

Here is a snippet of 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>

Below is a snippet of 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 + "/"); 
        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();
}

Answer №1

To keep track of the selected item text, you can store it in the session state and retrieve it when needed.

Make sure to add the OnSelectedItemChanged event to your dropdown list and set AutoPostBack to true for it to work as expected.

If you encounter any issues, this forum post might provide a solution:

Update:

In scenarios where the user does not change the dropdown value, adjust the UploadComplete method as shown below:

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

You can also set the default selected option for the dropdown list by including the following:

<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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging req.files for uploading multiple files at once

When it comes to handling a multiple file upload on the client side, I have encountered an issue with my HTML code. Here is what it looks like: form(method='post', enctype='multipart/form-data')#createReportForm input(type='file ...

Is there a way to automatically insert page numbers into every internal link on an HTML page?

When in print mode, I want to display links like this: <a href="#targetPage">link</a> but I'd prefer them to appear as: <a href="#targetPage">link (page 11)</a> (assuming the target page is on page 11 in the print preview). ...

Alter the command from 'require' to an 'import'

Utilizing https://www.npmjs.com/package/json-bigint with native BigInt functionality has been a challenge. In the CommonJS environment, the following code is typically used: var JSONbigNative = require('json-bigint')({ useNativeBigInt: true }); ...

How can I turn off warnings for angular-translation?

A series of translation related warnings are appearing in the browser console, and I am looking to suppress or disable all of these warnings to prevent them from being shown to the user. Warnings: Translation for Department doesn't exist a.(anonymous ...

Utilize data retrieved from an API to customize the appearance of buttons through the combination of React and Sass styling techniques

I retrieved data from an API and used it to create a list of buttons. The data I received includes names and color codes. { name: "bob", colorCode: "#DC7472" }, { name: "ben", colorCode: "#69DCD1" }, { name: &q ...

Utilizing NPM Package Configuration Variables with Docker Commands: A Guide

I have a unique file structure where my package.json contains a single variable called settings which defines the port for the application: package.json ... "settings":{ "port": "3000" }, ... In addition, I've set up a custom script to execute a ...

Is it possible to share a MySQL connection for cross-module usage in Node/Express by utilizing promise-mysql?

Currently, I am trying to import and utilize a database module within one of my controllers. Despite successfully establishing the initial connection, I am encountering an error when accessing any of my routes through the browser: "Cannot read property ...

Cart cannot function as a constructor

I'm currently learning express.js and trying to implement a shopping cart/session functionality into my project. Below is the code I have written so far, with a question at the end. Here is my cart.js: // Ensure that the file is required correctly b ...

React: The 'Redirect' function is not included in the export list of 'react-router-dom'

When I try to run npm run start in the terminal, an error message appears. 'Redirect' is not exported from 'react-router-dom', causing an import error. I have attempted various solutions like reinstalling node_modules, react-router-d ...

Querying two MongoDB collections simultaneously to locate a user based on their email address

I am working with two different collections, tutors and users, within my MongoDB database. Within the controller, I have a function called signin. In this function, I need to modify the condition so that it searches for a user in both the tutors and users ...

What is the best way to send multiple id values with the same classname as an array to the database via AJAX in Codeigniter?

Hey everyone, I'm facing an issue where I need to send multiple IDs with the same class name but different ID values to the database using AJAX. However, when I try to do this, only the first value is being picked up and not all of them. How can I suc ...

What is the best way to extract a single item from an array in Javascript and assign it to a different variable

I am currently dealing with an array of objects structured like this: contacts: [ { id: 1, name: "John Doe", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="066c696e6846616b676f6a2865696b">[emai ...

What is the process for deserializing child components within a list?

After retrieving data from the database, I am faced with extracting the BusPersonals values efficiently. Dealing with numerous fields in BusPersonals can be quite daunting. Is there a way to streamline this process without resorting to using autoMapper? p ...

Sleek carousel design with optimal spacing between images

Solving the Issue Utilizing Ken Wheeler's Slick plugin has allowed me to create a carousel on my website. However, I've encountered an issue where the images inside the <a> tag aren't evenly spaced and are even overlapping in some ins ...

Restangular is throwing an error because it cannot find the reference for _

I encountered an issue with Restangular where I'm getting the error message: Uncaught ReferenceError: _ is not defined from restangular when trying to use it. Code Snippet: <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angula ...

Having difficulty utilizing the express.session module in conjunction with HTTPS

I need to implement authentication and session creation on a HTTPS static website using expressjs. Here is the code snippet: app.js: // Set up the https server var express = require('express'); var https = require('https'); var http ...

Put a watch on a variable as soon as it is set

When initializing a variable, I want to use the $watch function in Angular without it automatically initializing right away. Is there a way to accomplish this? $watch $scope.$watch(function () { return $scope.character.level; }, function (ne ...

Troubleshooting "Module Not Found" issue with Vue.js single page component integrating Google Maps

I'm facing an issue while trying to integrate a Google Map from the Google Maps API into my Vue.js application. I have obtained my API key and made an attempt to display the map. However, upon running the app, Atom throws a "Module not found" error me ...

Exploring the depths of Nesting in Next.js Links

After trying to nest the Badge inside the Link element and wrapping it in an <a> tag, I managed to resolve some errors but one persists: https://i.sstatic.net/o1WfA.png import { useState } from 'react'; import Link from 'next/link&apo ...

Enter the variable into the parameter

I'm working with some Javascript code: document.getElementById("Grid").style.gridTemplateRows = "repeat(3, 2fr)"; I'm trying to insert a variable as an argument to modify my CSS style. When I attempt the following: "repe ...