Avatar of metropia
metropia
Flag for United States of America asked on

how to not lose variables values using calculate and submit button

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.
ASP.NETC#Web Languages and Standards

Avatar of undefined
Last Comment
Aaron Jabamani

8/22/2022 - Mon
yawkey13

please post code
metropia

ASKER
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
SOLUTION
yawkey13

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
metropia

ASKER
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
metropia

ASKER
am I instantiating the variables in the wrong place in the program?
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
metropia

ASKER
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 Jabamani

You are using some server memory by using session variables. You should use them when you have no other of way of handling.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.