Beginner question re postback

  • Thread starter Thread starter John W
  • Start date Start date
J

John W

Hello,

I have been wondering that everytime I do a submit on a button/form
(postback) it is using the same webform on the CS, how do I goto another
webform once I have done a postback and processed any code?

When I finally do goto another webform from the postback will all variables
and settings be sent along to this new web form?

Thanks

J
 
In Page Load always test for IsPostback and Not IsPostback so that when the
page is hit the first time different code is run.

If you click a button, then Page Load will run but maybe since IsPOstback =
True then you won;t do anything there.
Then your button handler code will run and you can do stuff.
The last line of code might be:
Response.Redirect("SomeOtherPage.aspx")

The variables will NOT be available on the next page unless you do
something.
Cache
Session
QueryString
etc.

e.g you could store them in Cache or Session during your button handler code
and then pull them out
when you get to the next page.

Or you could put them in a querystring:
Response.Redirect("SomeOtherPage.aspx?MyVariable=xyz")
 
In many cases, you don't need to go to another page since you can test for
IsPostBack and process the postback differently from the first page load.
If you do need to go to another page and have the first page data available
there, you can store the values yourself as mentioned in the earlier reply
or you can use server.transfer(newpage) and the new page's code will be
processed with the first page's form data available to it.
 
thanks joe,

great, any ideas which is the best route ?? you listed a few, are there any
pros and cons?

cheers

J
 
There are whole books on the subject.
I don't think anything I can say in a few lines is going to help!

Session is extremely useful and user specific. Requires lots of RAM.
Viewstate is also user specific - requires more traffic over the wire so it
is slower for the end user.
Querystring is great for passing small pieces of info in the URL like a PK
value.

Application is for all user but should be avoided in favor of Cache which is
the same thing but with more features.
(Application is more for backward compatibility.)
Cache can be set with priorities and expirations. You can also set
dependencies to expire it.
Very useful for application wide things that should be stored in RAM.

Server.Transfer is useful as stated in another message.
The main thing I don't like about it is that the URL does not change for the
user.
I also recently read that there may be a bug in it. Something about some
events not running correctly (or as anticipated) when using it. I tend to
stay away from it for these 2 reasons. YMMV.
 
Back
Top