How keep the value after the PostBack with a variable declared in a ASPX page

I need to keep some values stored in variables in an aspx page.

The problem is that when a PostBack is produced i lost the values...

Actually I store the values in Session Variables but i think isn0t a pretty practice.

Any idea?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul JacksonSoftware EngineerCommented:
what are the variables used for ?
the usual method of storing values that you want to keep after postback is to use a hidden field like
<asp:hiddenfield id="myhiddenfield" value="" ></asp:hiddenfield>
limmontreefreeAuthor Commented:
Hello In this case I need that after you press the button, the page redirect to Another Page. The redirected page can vary depending on several parameters.

When click the button, in the load event,  if is  postback I redirect to the correct page. The correct page url is stored in a variable, but in the recharge the data is lost if I don't put it in a variable session.

SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:

You may be putted your code into like this,

if page.IsPostback = false then
             session.content("value") = hiddenfiled.value

It is not proper use for keeping value at the time of postback.

put your code outside of the IsPostback like this.

session.content("value") = hiddenfiled.value
if page.IsPostback = false then
There are a few options to store values on servers which are persisted between postbacks. These include Session, ViewState, Database, FileSystem, Cookies etc. Session is the most commonly used between these. What is the reason for you to not like Session?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
limmontreefreeAuthor Commented:
Well I came from Windows programming and  I don't like because it seem like a trick not like a technics, but I'll use it if not be a better way.

Thanks all
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.