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

Handling Datatable: Executing an asynchronous function post an Ajax request

Upon receiving data from the web server, I want to manipulate it in Datatable. However, the response data is encoded and requires decoding using an asynchronous function called decodeData(). I attempted to call this async function in the dataSrc section as ...

JS Issues with generating accurate dates in JS/JS Date perplexities

Creating a custom datepicker has been a challenging task for me. I'm facing difficulties in understanding how JS Date works and need some assistance to bridge this knowledge gap. The issue arises when I attempt to generate dates using a for loop, resu ...

Trouble with installing Enmap due to better-sqlite3 error

For a while now, I've been struggling to get enmap installed. Despite searching the web exhaustively, I haven't come across any solutions that work for me. Every time I try npm i enmap, I consistently encounter this frustrating error: One part o ...

Create an element that can be dragged without the need to specify its position as absolute

I am having an issue where elements I want to drag on a canvas are not appearing next to each other as expected. Instead, they are overlapping: To make these elements draggable, I am utilizing the dragElement(element) function from https://www.w3schools.c ...

What is the best way to eliminate an Injected Script from my system?

I have added a script to my GWT Application using ScriptInjector ScriptInjector.fromUrl("js/jquery-1.7.2.min.js").setWindow(ScriptInjector.TOP_WINDOW).setCallback(new Callback<Void, Exception>() { @Override public ...

How can I populate a select dropdown list in Django using JsonResponse?

I've been working on displaying a list from my Django application in an HTML select option, but I'm having trouble getting it to show up. Also, I believe I need to assign IDs to the option values in the select list, but I'm not sure where to ...

"AngularJS directive mandating the use of the required attribute for internal control

I've encountered a challenge with this specific issue. We are using a directive called deeplink, which contains the following code: restrict: 'E', require: 'ngModel', scope: { smDropdown: '=smDeeplinkDropdown', s ...

Null session scoped managed bean encountered during an ajax request

Currently, I am utilizing JSF 2 alongside primefaces 2.1.3 with tomcat. My aim is to access the session scoped managed bean in the converter class using the approach below. MemberConverter{ public Object getAsObject(FacesContext arg0, UIComponent arg1 ...

Retrieving an array of various responses using Axios

My current code includes a function that retrieves exchange rates for various stocks: export const getRates = (symbole1, symbole2, symbole3) => { const res = [] axios.all([ axios.get(`${baseUrl}/${symbole1}`), axios.get(`${ ...

Deleting specialized object using useEffect hook

There's a simple vanilla JS component that should be triggered when an element is added to the DOM (componentDidMount) and destroyed when removed. Here's an example of such a component: class TestComponent { interval?: number; constructor() ...

Searching by multiple parameters in Angular.js

I have a script that scans through a field and highlights the words related to the search input. I want this script to not only filter by title, but also by name. How can I adjust the code to filter both the title and name when searching? <li ng-repeat ...

Attention: certain content may have been removed due to HTML sanitation

Hi there, I'm currently working on incorporating a search bar into a modal window by embedding HTML within the modal body. Here's how I've written the code: onClick() { const dialogRef = this.modal.alert() .size('lg' ...

What is the best way to showcase the information from this API on an HTML page using Vanilla JavaScript?

I am currently working on implementing an AJAX call to fetch data from a movie API online. Below is the HTML code I have written for this: <html> <head> <meta charset=utf-8> <title>Movie Database</title> ...

Not all databases are retrieved in the search query

When I make an API call to get all the Database entries, I am encountering an issue. The response I receive only includes a few databases instead of all of them. async function checkDatabases(item){ if(item.object == 'database') ...

Dealing with Unresponsive Commands in Discord.NET (C#)

I am currently working on developing a discord bot using discord.net that has the capability to fetch all variant Ids from an online store and then sends out discord messages with the variants listed in a specific format: var1 var2 var3 etc During my test ...

What are the steps to sorting in JavaScript?

I need help with sorting an array. The array I have looks like this: var temp = [{"rank":3,"name":"Xan"},{"rank":1,"name":"Man"},{"rank":2,"name":"Han"}] I've tried to sort it using the following code: temp.sort(function(a){ a.rank}) But unfortun ...

I am having trouble retrieving any data when using jQuery to post JSON data

I am struggling with some HTML and JavaScript code. Here is what I have: <html> <head> </head> <body> <script src="view/backoffice/assets/plugins/jquery/jquery-1.11.1.min.js" type="text/javascript"></sc ...

issues arising from a growing css division

I am facing an issue where the tiles on my webpage expand on hover, but some of them are partially covered by neighboring tiles. How can I resolve this problem? Here is the CSS code snippet: .tile { position: absolute; width: 86px; background-color ...

The operation to set a nickname in Discord.js was unsuccessful due to insufficient permissions

Recently, I started using discord.js to create a simple bot. Whenever I try to change the nickname by calling message.member.setNickname("Another Nickname").then(console.log, console.log); I receive the following error message: { name: ' ...

The candy stripes on a loading bar zebra assist in creating a unique and

I'm in the process of creating my portfolio and I'd like to incorporate unique animated loading bars, such as vertical or horizontal candy stripes, to showcase my coding skills. Can anyone suggest a specific programming language or tool that woul ...