Receiving a void value from the concealed field on the server end

When calling a JavaScript function and passing the value of a hidden field, I intend to use that value on the server-side. However, the hidden field's value is null.

Client-Side Function

function getDetails()
    {
        document.forms[0].HdnNode.value=tree_selected_id; //HTML Hidden Field.
        str="Cmp_12";
        str_array=str.split("_");
        var str_array1=str_array[0];
        var str_array2=str_array[1];
        document.getElementById("<%=HiddenNodeId.ClientId %>").value=str_array1;
        document.getElementById("<%=HiddenTreeId.ClientId %>").value=str_array2;                       
    }    

Server-Side Function

Public Sub InsertNodes(ByVal NodeId As String)
    Dim objErrorObj As New ErrorObj
    Dim ParentID As String
    ParentID = HiddenNodeParent.Value
    NodeId = HiddenNodeId.Value
    Dim NodeIDTree As String
    NodeIDTree = HiddenTreeId.Value
End Sub

Answer №1

In my code, I utilize hidden fields within UpdatePanels to send data back to the server for partial postbacks. Setting EnableViewState to true allows for whole page postbacks.

Here is an example of how it is implemented:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load" UpdateMode="Conditional" ChildrenAsTriggers="True">
    <ContentTemplate>
        <asp:HiddenField runat="server" ID="LinesBack" value="0"/>

        <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="10" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <img id="spinner" alt="spinner" src="../Pictures/spinner_30x30.gif" />
            </ProgressTemplate>
        </asp:UpdateProgress>
        <div id="Back" class="NewresultPanel" runat="server" ></div>
    </ContentTemplate>
</asp:UpdatePanel>

When accessing the hidden field in HTML, you can do so with this script:

var a = document.getElementById('<%= LinesBack.ClientID %>').value;

And in C#, you can assign values to the hidden field like this:

LinesBack.Value = CountRows.ToString();

Answer №2

In order to access the hidden field in the server-side code that was provided, you need to include the runat="server" attribute.

For example:

HTML

<input type="hidden" id="hidTest" runat="server" />

Server-side code

hidTest.Value;

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

A guide on initiating a get request with URL in React

Utilizing React for the frontend and express for the backend has been my approach. By defining get methods in my express like this:- app.get('/addBill',(req,res)=>{ // --first method res.render("addBill"); }); app.get(&a ...

Ways to determine whether one side of a selected div is not obstructed by other divs

I am working with some div elements that are all sized 100x100px: Below is the HTML code for the 3 blocks: <div id="plane"> <div class="tile tile3" block-id="1" style-id="3" style="left:50px; top:50px"></div> <div class="tile t ...

Mastering the art of utilizing _.debounce on VueJS data modifications

I'm currently developing a small application using vue.js where I am making some post requests to an API. I have implemented the watch method to monitor changes in the API, updating the component upon successful post requests. However, as the watcher ...

Error: Attempting to access an undefined property ('call') on Next.js is causing a TypeError

Exploring the realms of Next.js and Typescript for a new project! My goal is to utilize next.js with typescript and tailwind CSS by simply entering this command: npx create-next-app -e with-tailwindcss my-project Smooth sailing until I hit a snag trying t ...

``Is there a way to effectively assess the Angular UI-Grid cellTemplate function in the attribute value only when it is displayed

Utilizing angularjs and ui-grid with a custom cellTemplate, each cell contains an object referred to as COL_FIELD. This object is passed to a function that generates an image data URI used in the src attribute of the cellTemplate to display images within e ...

The image command fails to display the image

On my ASP.NET page, I have an Image control. Despite setting the image URL in the properties window, the image is not displaying when I run the application. Here is the relevant source code: <asp:Image ID="imgMain" runat="server" ImageUrl="~/P ...

Retrieving the Identity Value after Inserting a Record into an MS Access Table

In my VB .net 2010 project with a MS Access 2010 Database, the wizard generated a DataSet containing all the tables from the database. This allows me to easily use the following code to insert a new customer: Me.CustomerAdapter.Insert("New Customer") An ...

The map fails to load on the HTML page

I am struggling to load a map into my HTML page from a file located in the app folder. Despite using the correct code for inserting the map, it still does not load properly. <!-- Contact section start --> <div id="contact" class="contact"> ...

Why is the startsWith function not returning the expected result in my code? What could be causing this issue?

I have a code snippet that sorts a list based on user input, but it fails if the user's input contains spaces. How can I modify the code to handle inputs with spaces without removing the spaces between characters? For example, if the user input is &ap ...

another option besides the nextElementSibling

I have a unique code that applies a style to the following div when another div is clicked, using nextElementSibling. var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < acc.length; i++) { acc[i].addEventListener("clic ...

I am looking to implement a feature that will disable unchecked checkboxes based on certain conditions in a

Upon selection of an option from a dataset, an API call is triggered. The API response includes an object with a nested array, whose values are listed as checkboxes. Additionally, the API returns a key named choose(const name primaryMax) indicating the max ...

Creating a JavaScript Redirect Modal in Laravel

When a user likes a story on the card, they can save it by clicking the "save" button. I handle this action by calling the savePost function in my .js file. However, if the user is not logged in, I redirect them to the login page using "location.replace( ...

Audio transition on hover over image

I'm currently designing a website and I have an image depicting a house with windows. I would like to create an interactive element where the face of Goldilocks pops up in one of the windows on mouseover, accompanied by sound. I envision the face movi ...

Tips for passing input fields from a React Function component to a function

How can I retrieve the values from 4 input fields in my react functional component using a function called contactMeButtonPressed? The inputs include name, email, company name, and message when the contact me button is clicked. Do I need to implement stat ...

What is the best way to divide React Router into separate files?

My routes configuration is becoming cluttered, so I have decided to split them into separate files for better organization. The issue I am facing is that when using 2 separate files, the routes from the file included first are rendered, but the ones from ...

I am having trouble unzipping the file

I encountered an issue while attempting to download a .zip file from Discord and extracting it using the decompress package. Despite not returning any errors, the package did not get extracted as expected. (The file was saved and downloaded correctly) co ...

Error message: "An issue occurred with the Bootstrap Modal in

I've designed an AngularJS app like so: <!DOCTYPE html> <html ng-app="StudentProgram"> <head> <title>Manage Student Programs</title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2. ...

Obtain the selected option's value using Angular

Having an issue with my user.model.ts file. I have a list of users that I can edit by clicking on a button that filters the user's data and puts it in a bootstrap modal. I'm using [ngModel] in a select tag to get the country of my user, but when ...

[VUE Alert]: Rendering Error - "Sorry, there is a type error: object is currently undefined."

<script> const app = new Vue({ el: '#app', data:{ results:{} }, mounted() { axios.get('{{ route('request.data') }}').th ...

Incorporate Stripe Elements into your Nuxt Js application

I recently managed to integrate Stripe into my React + Spring Boot application by following the guidelines provided in this documentation: https://stripe.com/docs/stripe-js/react. I used it in my React class component. Now, I am transitioning to Nuxt from ...