Forum Moderators: open

Message Too Old, No Replies

super .net newbie

passing data between pages

         

f00sion

9:20 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



what is the best way to pass parameters between pages in asp.net? I was under the impression that it is outdated to use hidden form fields or the querystring. Is there some special way of doing it using a linkbutton or something?

TheNige

10:57 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



In ASP.Net people generally use one form (page) to do all of the processing for a task. You can use "Panels" to hold certain form elements and then hide them as needed. For instance, you can have Step 1, Step 2, and Step 3 all on the same page and you display each of them once the previous step is complete.

All of the inputted data is stored in the ViewState for those form elements and can be accessed even if the panels are hidden. So, in other words, there really is no need to pass form element data to another page.

If you really need to though you can always pass the data still using querystring, and hidden form fields, the Session objec, and the Cache object.

By default though, ASP.Net pages are made to use PostBacks (pages that post to themselves).

Xoc

11:25 pm on Feb 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you do need to pass info between pages, you can use all the traditional methods: post or querystring, cookies, or Session variables. That hasn't really changed between ASP and ASP.NET. What's new is the postback mechanism TheNige mentioned using ViewState.

f00sion

1:34 am on Feb 12, 2004 (gmt 0)

10+ Year Member



I figured out using the postback stuff to change the query for my datagrid and whatnot..it just seems like it would get a little hard to manage with everything on one webform.

TheNige

3:41 am on Feb 12, 2004 (gmt 0)

10+ Year Member



Not sure if you are using VS.Net or not...but that is why they have #Regions to hide/group code...

Panels are good ways to group the items on the ASPX page.

Also, be sure to do your actions in the control events....don't try to do each action in the Page Load...

f00sion

6:09 am on Feb 12, 2004 (gmt 0)

10+ Year Member



yeh, im using vs.net and ive noticed that nifty region feature. Thanks for the help, its so hard after doing classic asp for so long to think of the different pages as windows forms and code accordingly.

TheNige

7:41 pm on Feb 12, 2004 (gmt 0)

10+ Year Member



Well, once you get into doing things the .Net way...you will never want to go back to classic ASP. I wince everytime I have to touch an old project because ASP.Net is so powerful and easy.

f00sion

10:42 pm on Feb 12, 2004 (gmt 0)

10+ Year Member



yeah, im starting to see it. So if I need to keep track of an int or string during a postback should I store it in the viewstate collection?

TheNige

11:06 pm on Feb 12, 2004 (gmt 0)

10+ Year Member



If you only need to keep track of it for that page then put it in the viewstate. If you need to track it over multiple pages then put it into the session or cache object.