Reputation: 8150
In an application, I draw some data from a database which will be used by several methods. Is it a good idea to write the data to hidden fields when first drawn or should I draw the data again when needed?
Upvotes: 1
Views: 1942
Reputation: 3659
It is usually a good idea to have single source of truth, the 'master' for your data. Now you may want to replicate this data for performance reasons, but until you need it, you shouldn't.
Upvotes: 0
Reputation: 4943
It depends on what the data is and how you're going to use it.
What kind of data is it?
If it's data that should be secured, such as PHI or other, never store it this way. Use session state. Otherwise, go to the next question below.
Where will you use it?
If it's used in the code behind, use viewstate or session state. If you plan to consume it using jquery or javascript and it doesn't need to be secured, a hidden field is fine.
Upvotes: 2
Reputation: 7614
Hidden field means you send those data to the client and the client uploads the data back to you on submit. It may be a security or a performance problem. But it all depends on your scenario.
You may want to rather use a Session
Or Caching
Upvotes: 0
Reputation: 10870
It depends what you are trying to save or hold.
Privacy
If the data needs more security then don't save it in hidden fields.
Size
If the data is small then its fine else hidden field is not efficient way.
Upvotes: 3
Reputation: 13275
I say it depends on your need for security. Remember hidden fields are client-side and therefore editable by the end user.
If these fields are going to be posted back or used for anything more sensitive than a bit of interaction, then it may be safer to grab it from the database each time.
Upvotes: 1
Reputation: 45083
This depends, I suppose, on a couple of factors that would include, but not be limited to:
For the most part, the decision is purely down to circumstance; and we don't necessarily have the circumstantial information.
Upvotes: 0
Reputation: 8152
If you mean a private field, then yes, that's a good idea as long as the data is the same for all of the methods using it.
Upvotes: 0