Forced to use too many hidden fields; search for an alternative approach

I am looking for a better approach for this.

I have about 70 - 80 hidden fields on my page. These hidden fields are initialized on the server side and then used on the client side for validation, calculations, etc. using java script.

I wanted to know if there is another alternative approach to using hidden fields in asp.net. I think these many hidden fields increase page size and therefore affect the performance of my web page, and I want to end it.

FYI: I am working on an asp.net web application.

+4
source share
4 answers

validation, computation using javascript is best done when JSON is used as the underlying data. Just assign the server-side JSON JS variable, and then use it in JS as an object or array.

+1
source

I was going to assume that you describe the information as a data structure, serialize it in JSON , include it in <script> (assigned to a variable that you can access with a confirmation code).

... but you will still receive data for the client, so performance problems will not disappear.

You can see how to provide it in an external file, so it can be cached, but I do not know enough about how to reuse data, if possible.

0
source

In the HTML header, add some javascript initialization variables with the required data:

 <script type="text/javascript"> var option1 = true; var option2 = 'some text'; ... </script> 

You can then access these variables to test your javascript.

0
source

Agree with the JSON and JS ideas promoted here - you send the information necessary for your calculations and validation in a harsh format, and it will not be sent back.

This provides a direct means of accessing your data, rather than some jQuery / DOM search, to get your hidden field values, increasing computational performance.

If you're talking about performance in terms of load and rendering times, and if the client-side JSON representation of your data is huge, then your only other option is to make AJAX calls to do server-side computing and validation, so your large dataset never moves down the wire in any direction. Be careful though round-trip AJAX time to get a response from the user.

0
source

Source: https://habr.com/ru/post/1306896/


All Articles