An effective and lightweight method for submitting multiple value fields in a form to an ASPX web form

Let me provide a clearer explanation of the question I have: On my aspx webform, I am creating an entity and capturing simple data. This entity can have multiple child entities linked to it in a one-to-many relationship, all created from the same form. I'm avoiding using heavy ASP.NET components such as datalists or custom components for this purpose. What I currently do is open a dialog on the page with a combobox populated through an AJAX call. When the user selects an entry and saves it, I add that choice to a JavaScript collection which displays the selections in a list on the client side. How can I submit this collection when the user submits the form, and how can I parse it back on the server? My idea is to use JSON to store, serialize, and then deserialize the data. Is this a reliable approach?

Answer №1

If you want to share it, here's how you can do it:

function sendPostData(data){
var jsonString = JSON.stringify(data);
$.ajax({
    type: 'POST',
    url: 'your destination URL',
    data: jsonString,
    success: function (){
        alert('Success! Data posted');
    },
    dataType: 'json'
});

};

On the server side, you can use json.net to deserialize the JSON string like this:

// Utilize JSON.Net
public static void HandlePostRequest(string jsonData)
{
    var deserializedObject  = JsonConvert.DeserializeObject<MyObjectType>(jsonData)

    // Process the object accordingly
}

Alternatively, if your page includes a scriptmanager, you can make use of PageMethods along with it. Check out this resource for detailed information.

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

Using Laravel and Inertia App to fetch data from an API endpoint

I am currently using Laravel with InertiaJS and VueJS for my App. Jetstream scaffolding is handling all the authentication tasks within the app. However, I am facing an issue with a few pages that need to access the api.php routes in my project. For examp ...

Obtain a list of object property names in an ARM template

Is there a method in an ARM template to extract an array containing the property names of a JSON object? I couldn't find any clear information in the documentation. The closest possibility seems to be using length(object) to retrieve the count of prop ...

"Discover the method to access values within an associative array or object in an Ember template by utilizing a

When working with Ember, the traditional syntax for looking up array values by key is to use the .[] syntax. For example: {{myArray.[0]}} However, I have encountered an issue when trying to perform a lookup on an associative array. Even though I have a s ...

Using Java to extract information from JSON data

Looking at the JSON below { "qty": "1", "dswer": 0, "bag": { "dm": "2", "rate": "---", "ghy": "3013-04-05T00:00:00.000-05:00", "dee": "301304", "desc": "SSAA APR 05 2013 --- BGG" } } If the rate at ...

What is the best method for saving this.score to a text file in order to create a high score leaderboard? (AJaX)

Is there a way to save this.score to a text file using ajax so that highscores are displayed when the game is over? Also, I would like an alert message saying "Your score has been saved successfully". I am not very familiar with ajax, so any detailed expl ...

Spring MVC enables the effortless return of created objects using REST (Representational State

When making a REST call that accepts a JSON object like a person, and after validating and saving it to the database, there is a need to return the newly created JSON Object. The common practice is to return 201 Accepted instead of immediately returning th ...

Generating a compilation using ng-repeat

HTML <html lang="en" ng-app="map" xmlns="http://www.w3.org/1999/xhtml"> <body> <div ng-controller="topbarController as topbarCtrl"> <div ng-repeat="pages in topbarCtrl.topbar"> {{pages.page}} </div> &l ...

Resolving ASP MVC problems through knockout.js in dialogues

As a newcomer to KnockoutJS, I'm facing some challenges in grasping the most effective way to leverage Knockout's databinding. You can view my code on this Fiddle. In my current project, I use dialog popups to populate tables with values. Howeve ...

What is the process for constructing a regular expression (regex) in JavaScript to validate an id?

My validation requirements are relatively straightforward, but as someone who is new to regex, I am in need of quick assistance. The format should be either 1234567890 or 123456-7890, allowing for any number ranging from 0 to 9 and a total character length ...

Why is the lower sub-component positioned above the rest of the page?

I have set up a sandbox environment to demonstrate an issue that I am facing. The main problem is that when I click on "Option 1" in the main menu, a new component appears where a bottom sub-component (named BottomControls.js) is displayed at the top of t ...

Safari is throwing an error message stating that FormData.entries() is not a valid function

My ajax function for posting an image works perfectly in Chrome and Firefox, but Safari and iOS Safari are having issues with it. To create and append the value, I am using this code: var ajaxImage = new FormData(); ajaxImage.append('file-0', $ ...

Function cannot be executed following the completion of JSON loading

Check out this link for an interesting demonstration. It displays the name 'Antonio' after a JSON request is completed. Unfortunately, there seems to be an issue with the jQuery function not executing properly. Can you ensure that document.write ...

"Interactive demonstration" image toggle through file upload

I have a project to create a "demo" website for a client who wants to showcase the template to their clients. A key feature they are interested in is allowing users to upload their logo (in jpg or png format) and see it replace the default logo image insta ...

As the page is resized or zoomed in and out, the div elements start shifting in different directions

When I apply position:absolute to prevent the elements from moving when zooming in and out of the page, they all end up congregating in one place. Can anyone help me with this issue? None of the solutions I've found have worked so far. I'm develo ...

Sharing properties across various components with Next.js

I'm still getting the hang of using Next.js and encountering issues with sharing data between components. Currently, I have a setup involving three components: //index.js function App() { const choices = [] for (let i = 1; i < 101; i++) { ...

Differences between jQuery form.id and form.id.value

Currently, I am working on a dokuwiki plugin and have stumbled upon an interesting issue regarding how javascript stores element ids. I am a bit confused about what is happening... Here is a snippet of code from the dokuwiki linkwiz.js file that checks if ...

Are certain browsers unable to play dynamically generated HTML5 audio files?

While working on my project, I encountered an issue with creating and controlling an audio element in JavaScript. The element works perfectly fine in Firefox, Chrome, and Opera; however, it fails to function properly in IE and Safari. In these browsers, ...

Structure using JSON for silent push notifications on iOS versions 9-10

Our team is currently working on an app that will be able to receive remote push notifications. We have learned about the two types of notifications available, which are "normal" and silent. We are looking to understand the JSON structure specifically fo ...

Silly problem arising from the animate feature in jQuery

Apologies for my poor English. I am facing an issue with the animate function of jQuery in my code snippet. It seems to work fine at line 2, but it doesn't work at line 3. Can someone help me understand why? $('.opac').hover(function(){ ...

A valid ReactComponent must be returned in order to properly render in React. Avoid returning undefined, an array, or any other invalid object

While working on my react application, I came across an error that I have been trying to troubleshoot without any success. It seems like I must be overlooking something important that could be quite obvious. *Error: VideoDetail.render(): A valid ReactComp ...