• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 837
  • Last Modified:

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?

3 Solutions
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?
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now