how to not lose variables values using calculate and submit button

metropia
metropia used Ask the Experts™
on
I have an asp.net page/ form with two button.

the first button is enabled and it is used to calculated some fields based on other fields inputs.

after the calculation is completed, then the second button becomes enabled, and allows the user to submit the user entered values, and the calculated values into a database table.

my problem is that when i click the second button, the variables and their values are lost, because i instantiate them at the very beginning of the page.

how can i do so that the values are not lost when the second button is clicked and the field values are already there?

I can post my code if my question is not clear


Thanks you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
please post code

Author

Commented:
the first button is btnCalculatedFields_Click

second button btnSubmit_Click

when i click on it, all the variables are set back to their original state.

thanks for your help.
DataEntry.aspx.cs
Commented:
You are running LoadSubjects() every time the page refreshes via the Page_Load function.  Wrap the function call in an if statement to check post back:

if (!IsPostBack)
            {
                LoadSubjects();
            }
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
Hi, I did that but still I lose all the values.

I click the calculate fields button, I get all the values, calculated and from the form.

When I click the submit button, and go into the insert statement, the date is null,
and all the calculated fields are set to 0.

Author

Commented:
am I instantiating the variables in the wrong place in the program?
Why don't you get the values from text box controls instead of variables?
Aaron JabamaniTechnical Architect
Commented:
When the first button is clicked, compute the values and store in a hidden variable . When the second button is clicked, get the values from the user and the computed values from the hidden variable and store them.

Author

Commented:
is it a good option to use session variables?
I added a few and they seem to work, but I am unsure as to whether is recommendable or not to use them.

Thank you.
Aaron JabamaniTechnical Architect

Commented:
You are using some server memory by using session variables. You should use them when you have no other of way of handling.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial