Which option is better from Best practices point of view and from performance point of view?
Which option is better from Best practices point of view and from performance point
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What do you need?
a variable that’s alive from the moment the ASPX page gets created and starts its lifecycle and that will be disposed with the page instance once the HTML is rendered back to the client?
or a variable that will “survive” postbacks and be sent back to the client with the HTML and come back to the server the next time the page is requested??
For option #1, you’re fine and should definitely use a normal variable inside your page class – no need for ViewState.
If you need option #2 – variable value needs to be saved across postbacks and come back with the next request – then there’s only ViewState as an option – storing it in a local variable in your page class won’t do.
Marc