Retrieve the JavaScript variable `window.myvariable` within the ASP code-behind of a child form

In my scenario, I am utilizing a parent form that initiates a child form through the following javascript code in order to transmit a json object.

        var w = window.open("childForm.aspx");
        w.myJsonObj = myJSONObject;

I am currently seeking assistance on how to retrieve and access this variable within the onload event of the childForm.aspx so that I can proceed with deserialization.

Answer №1

One important thing to remember about Javascript variables is that they are limited to the client-side, making them inaccessible server-side from code-behind. In order to utilize these variables on the server-side, you must find a way to store the value where the server can retrieve it.

There are various approaches you can take, but here's a suggestion: create a hidden field to securely hold the value, assign an id to the field, and add the runat="server" attribute (this makes it accessible from the server-side). Then update your javascript code to fill this hidden field with the desired value.

Hidden field:

<asp:HiddenField id="SomeUniqueID" runat="server"/>

Javascript (without JQuery):

document.getElementById('<%= SomeUniqueID.ClientID %>').setAttribute("value", myJSONObject);

Javascript (with JQuery):

$('#<%= SomeUniqueID.ClientID %>').val(myJSONObject);

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

The "begin" parameter of the Angular limitTo filter appears to be ineffective in Angular version 1.3

Currently, I am attempting to implement a pagination feature on an array of users using Angularjs 1.3. ng-repeat="user in users | filter: searchText | orderBy: 'lastName' | limitTo:pageSize:startPosition track by user.lanId" I specifically want ...

Is it possible to export a table to a CSV file using jQuery/JavaScript code, no matter how large the table is? Check out the jsfiddle link for

Check out this link to view the table and code: http://jsfiddle.net/KPEGU/485/ I am experiencing an issue with exporting the table to Excel CSV. When I click the export button, a blank CSV file is generated without any data. // The following JavaScript ...

Sending an Angular scope variable to JavaScript

I am working with an angular scope variable that is being used in ng-repeat. My goal is to create a chart that starts from a specific date, ends at another date, and includes a marker for the current day. I am utilizing loader.js for drawing the charts in ...

How can you use Knex to order the results for each WHERE clause in a SELECT query?

When querying a database using knex, the desired results should be ordered in a specific manner. The current code provides the required results but lacks the expected order. knex("FRUITTBL") .select("FruitTag", "FruitName", ...

Manipulate the order of JSON data columns when using the Json() function in ASP.NET MVC

I have created a database table called Articles which contains the following columns: ID, Title, Excerpts, Content In my corresponding MVC model class: public class Articles { public int id { get; set; } public string Title { get; set; } pub ...

Guide to updating the content of an input field

As a newcomer hobbyist, I'm attempting to automate my web browsing experience. My goal is to have the browser automatically fill in my username and password, and then click the sign-in button using a combination of JavaScript and Tampermonkey. This me ...

Is there a way to effectively alter an object that has been assigned in a separate file?

Seeking Assistance: I am facing an issue in my current project where I need to store a javascript object in an external file and then export it using module.exports. The challenge now is that I want another file to be able to modify a specific value withi ...

Learn the step-by-step process of cropping and zooming an image using the react-image-crop

I am looking to implement zooming and cropping functionality for an image using react-image-crop instead of react-easy-crop. Currently, the cropping does not take into account the zoom level set by ReactCrop's scale property. I want to be able to zo ...

Using json_encode with chart.js will not produce the desired result

I am attempting to utilize chart.js (newest version) to generate a pie chart. I have constructed an array that I intend to use as the data input for the chart. This is the PHP code snippet: <?php if($os != null) { $tiposOs = array('Orçamento ...

Tips for extracting variables from a querystring in Express?

I am trying to retrieve values sent to the server: "/stuff?a=a&b=b&c=c" Can you please advise me on how to extract these values using express? So far, I have attempted... app.get( "/stuff?:a&:b&:c", function( req, res ){}); ...but unfo ...

Transitioning from one bootstrap modal to another in quick succession may lead to unexpected scrolling problems

I'm facing a challenge with two modals where scrolling behavior becomes problematic when transitioning from one to the other. Instead of scrolling within the modal itself, the content behind it is scrolled instead. In order to address this issue, I im ...

Extracting data enclosed in double quotes from a JSON list retrieved through a curl request

I have been trying to access an online JSON file and download it, however, I am encountering difficulties in parsing the data. Specifically, I am looking to extract IP addresses that are enclosed within double quotes from the JSON file. While I can use jq ...

The function json_encode() will produce a result which is not

I recently encountered a strange issue where a var_dump of json_encode resulted in a boolean value. After unserializing an array and verifying its validity, I performed a var_dump and here is a snippet of the result: array (size=3) 'id' => st ...

Is the input disabled when clicked on?

To ensure the end-to-end functionality of my application, I have implemented a scenario where upon clicking a spinner button, both Username and Password input fields are disabled before being directed to a new page. My testing methodology involves verif ...

What is the best way to extract data from an array of objects using jquery and javascript?

Here is the structure of my array: var $obj = { 'sections1' : { 'row1' : { 'key1' : 'input1', 'key2' : 'inpu2' }, &apos ...

Curl encountered an issue while trying to resolve the host using the riak protocol

In my current bash script, I am reading a csv file and inserting data into Riak. #!/bin/bash # Set the field separator as "," using $IFS # Read line by line using while read combo while IFS=',' read -r Num_Acc senc catv occutc obs obsm choc ma ...

Error: The hook call is invalid and can only be made within the body of a function component in ReactJS

Hello everyone, I am currently facing an issue with saving the lat and lng variables in the state within a hook. When trying to do so, I encounter the following error message: "Error: Invalid hook call. Hooks can only be called inside the body of a functio ...

Can you explain the significance of the v-on="..." syntax in VueJS?

While browsing, I stumbled upon a Vuetify example showcasing the v-dialog component. The example includes a scoped slot called activator, defined like this: <template v-slot:activator="{ on }"> <v-btn color="red lighten-2" ...

Adjusting the width of a nested iframe within two div containers

I am trying to dynamically change the width of a structure using JavaScript. Here is the current setup: <div id="HTMLGroupBox742928" class="HTMLGroupBox" style="width:1366px"> <div style="width:800px;"> <iframe id="notReliable_C ...

Displaying a loading screen while a jQuery ajax request is in progress

Currently, I am attempting to display a loading div while waiting for an ajax call to finish. Despite experimenting with various methods, I have not been able to consistently achieve the desired outcome. In my present code, everything functions properly o ...