Linked Pages in ASP.NET with persistant data

I want to design an ASP.NET application with 3 forms. Each of the forms is related to each other as follows,
1. Search Criteria Form - user fill out fields to restrict a database query eg. date range, transaction # etc.
2. History Form - displays records in a grid view that match criteria from Search Criteria Form
3. Transaction Details Form - shows individual transaction selected from the history forms GridView

The behaviour between these related forms should be
1. Initial Form is Search Criteria Form - user fills out fields - creates sql query
2. Submit event from Search Criteria Form brings up History Form with records matching sql query
    2a. Cancel Button - returns to Initial Form with user filled out fields retained from original submission
   2b. Transaction Details Form loaded by selecting a row in the GridView
3. Cancel Button on Transaction Details  Form returns to Search Criteria Form while retaining the already set sql query

My question is how to make the form display and data persist as the user navigates between the forms as described above.  My thinking so far is that I could use either hidden fields or session variables. I am new to ASP so there may be even better options.

Any and all advies would be appreciated.



Who is Participating?
samtran0331Connect With a Mentor Commented:

I wouldn't use hidden fields, ASP.Net, by itself keeps a hidden field called "viewstate" that tracks all the controls and the data in the controls.
So besides using session variables, you could instead use querystring variables or "server.transfer"
Server.Transfer works kind of like "Response.Redirect" except that you can only use "server.transfer" to pages within your app, and the page that it sends you to can get the variables of the page it came from...
page1.aspx has a textbox1, on a button click you do:

on page2.aspx, you can get the value of textbox1 on page1 with:

Personally, I would set up the search page to send querystring variables to the history form.
And I would actually not have the 3rd page and the history form would be a Gridview to show the search results and on clicking a row in the gridview, show a DetailsView control...
DaveChoiceTechAuthor Commented:

Thanks for the info re viewstate info and server transfer. The 3'rd form is the transfer details form. It takes up almost the entire screen using tables to place controls etc. Is this practical with a detail view?
Also, how can I keep the values in the first form when I return to it from the S'cd form?

>>It takes up almost the entire screen using tables to place controls etc. Is this practical with a detail view?

You don't necessarily have to show the grid when the DetailsView is visible. You can hide the Gridview when the DetailsView is visible and vice versa.

>>Also, how can I keep the values in the first form when I return to it from the S'cd form?

Well, if you have a button that has a javascript:history.go(-1);
wired to it, then it will pull the page from the browser cache which would include the textbox/search criteria.
If you want to manually control it and make sure the values go back, then I guess I would use Session variables.

The main reason I like to use querystring variables for search pages, is that you'll notice most major search engines do this...and it gives you the option of loading the second page from a link...
like if you wired up form 2 (let's call it history.aspx) to catch querystring variables, then you could bookmark search criteria or send the link in the email with something like:
which would allow you to bypass the search page altogether as long as you send history.aspx the correct variables...
i would suggest that you can build all of this in a single page .. the top section of the page is the search section with the submit button .. down below you can have a grid which is editable .. with editcolumn .. in the click event ot the submit button, do the search and bind the result to the gridview .. now the user has the option to edit each row as he wants .. now there is no need to worry about persistance because it is all in one page and viewstate will manage all of it for you ..

sorry samtran .. seems to have repeated some of things you had mentioned above ..
All Courses

From novice to tech pro — start learning today.