Reviewing the dropdown checklist according to the information stored in the database

I am looking to validate the dropdown checklist based on data stored in a database.

Here is my script:

<script>
    function myValidationFunction(parameter) {
        $(document).ready(function () {
            $('#ContentPlaceHolder1_s10').val(parameter);
            $('#ContentPlaceHolder1_s10').dropdownchecklist('refresh');
            $('#ContentPlaceHolder1_s10').dropdownchecklist();
        });
    }
</script>

This is my C# page:

int[] parameterArray;
parameterArray = new int[] { 1,2,3 };

pl.qid = questionID;
Profile.questionid.questionID = questionID;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script     type='text/javascript'>myFunction("+para+");</script>", false);

I have been struggling to find a solution. Can anyone provide guidance on how to:

Verify the dropdown checklist based on values from a database?

Thank you in advance!

I am currently using the following dropdown checklist plugin:

Answer №1

When using RegisterStartupScript to output a string of Javascript on the page, it is important to properly format the para variable into a correct string representation of its values. Otherwise, you may end up with an output like myFunction(System.Array).

To achieve this, create a string that contains a comma-separated list of the values in para. You can use the String.Join() method for this:

int[] para;
para = new int[] { 1,2,3 };

pl.qid = questionID;
Profile.questionid.questionID = questionID;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp",
    "<script type='text/javascript'>myFunction([" + string.join(",", para) + "]);</script>", false);

This will correctly output myFunction([1,2,3]);.

If you encounter issues with server-generated javascript or html behavior, it's always a good practice to check the view source first to understand what is being output and identify areas that require investigation.

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

Incorporating a JavaScript npm module within a TypeScript webpack application

I am interested in incorporating the cesium-navigation JavaScript package into my project. The package can be installed via npm and node. However, my project utilizes webpack and TypeScript instead of plain JavaScript. Unfortunately, the package is not fou ...

Tips for optimizing the sequencing of 3 ajax requests, with the output of one request serving as input for the subsequent two requests

I'm currently working on a solution for chaining 3 ajax calls where the result of one call feeds into the next two. Here's the scenario: // Invoke the ajax calls firstAjax('mypage.gng','john-doe').then(secondAjax, thirdAjax) ...

The ajax function does not provide a response

Can you help me figure out why this JavaScript function keeps returning 'undefined'? I really need it to return either true or false. I've included my code below: function Ajax() { var XML; if(window.XMLHttpRequest) XML=new ...

What steps are involved in developing an Angular library wrapper for a pre-existing Javascript library?

Imagine having a vanilla Javascript library that is commonly used on websites without any frameworks. How can you create an Angular library that can be easily installed via npm to seamlessly integrate the library into an Angular application? The process o ...

Why is the deployed Express server failing to establish a session?

After deploying a node express server on Digital Ocean, I encountered an issue where the session was not being created. To address this, I implemented a store to prevent memory leak and included app.set('trust proxy', 1) before initializing the s ...

Switching a VB.net website to C#

I'm in the process of updating an older website from VB to C#. I've been using Telerik's online code converter to help with the transition, but I've hit a roadblock: The NavBar.ascx file simply contains some ASP hyperlinks to create a ...

It appears as though the promise will never come to fruition

I am currently developing an application that is designed to search for subdomains related to a specific domain and store them in a database. The application retrieves data from crt.sh and threatcrowd. One of the functions within the application parses th ...

Class variable remains unchanged following AJAX request

Upon completion of the ajax request, two integers are received - this.N and this.M. However, these values are not being set by the storeDims() function even though the correct decoding is done on the dims variable. This implies that I am unable to access ...

Run the function multiple times by substituting a portion of the argument in a sequential

I am facing a challenge with a method (exampleObj.method) that requires arguments of an object and a function. The code snippet is as follows: exampleObj.method({ name1: 'string1', name2: 'string2', name3: &apos ...

socket.io establishes several sockets for each connection

At times, when the server is experiencing some load, connecting to the page may result in multiple sockets being created. If there is significant lag, the connection may never be established while additional sockets are generated every second indefinitely. ...

Ways to dynamically toggle visibility and hide elements by clicking outside the specified div

I have a div that, when clicked, displays a contact us form. This form toggles between being visible and hidden. How can I make it hide when clicked on another part of the document? Here is the code: function showContactForm(){ var formWidth = &apos ...

What is the functionality of named function expressions?

After coming across an intriguing example in the book labeled as a "named function expression," I was curious to delve into its mechanics. While the authors mentioned it's not commonly seen, I found it fascinating. The process of declaring the functi ...

Is it normal for ASP.NET memory usage in IIS to be significantly higher than in DevEnv?

Hello there! I am facing a challenge with my ASP.NET application that is designed to scrape data from multiple external pages, extract the relevant information, and present it in a table format. The total amount of data retrieved is approximately 3-4MB, r ...

Latest Information Regarding Mongodb Aggregate Operations

Struggling to toggle a boolean value within an object that is part of a subdocument in an array. Finding it difficult to update a specific object within the array. Document: "_id" : ObjectId("54afaabd88694dc019d3b628") "Invitation" : [ { "__ ...

Invert the motion within a photo carousel

Is there anyone who can assist me with creating a unique photo slider using HTML, CSS, and JS? Currently, it includes various elements such as navigation arrows, dots, and an autoplay function. The timer is reset whenever the arrows or dots are clicked. Ev ...

Executing a C# program that sends a web request without using JavaScript

My goal is to programmatically download the contents of a website, but it seems like this content is being loaded through ajax calls. Interestingly, when I disable javascript in my browser, only one request is made by the page and all the content is displa ...

Guidelines for converting a number into an array of strings using JavaScript

Task: Write a function that takes a number and returns an array of strings, each element being the number cut off at each digit. Examples: For 420, the function should return ["4", "42", "420"]; For 2017, the function should return ["2", "20", "201", "2017 ...

Create a setup page upon initial login using express.js

Currently, I am implementing Passport.js for user authentication on my express.js application. I aim to display a setup page upon the initial login of the user. Is it possible to achieve this using Passport? ...

Locating items based on checkboxes and dropdown selection

My goal is to calculate the sum of certain numbers based on checkboxes and a select option. Below is the code I am using: <div class="container"> <select> <option value="1">1</option> <option value="2">2</option> <o ...

Challenges encountered in converting JSON objects into an HTML table

My goal is to convert a JSON object into an HTML Table using the following code: JSONSelect.forEach(selecRow, options, function (queryResult) { var sem = $.trim(JSON.stringify(queryResult, null, ' ')); console.log(sem); $.getJSON(&ap ...