简体   繁体   中英

How to move to the next page and then come back to previous page and also retaining its values ASP.net

I've two text boxes in one page and after those text boxes two separate search buttons, search buttons redirect to another page where user searchs and result is displayed in a grid, there can be multiple results, each row of grid contains 'select' command so that when user clicks on select of perticular row its data is selected and page redirects to previous page and data of row is displayed in textbox..

I've done so far. This is what I want to do:

Since there are two textboxes, two separate search buttons, what I am experiencing is when user selects 1st data for 1st textbox and searchs for 2nd text box then while returning for 1st page after 2nd search, 1st textbox becomes empty, What I want is that it should contain the value user has entered before.

textboxes should keep the value. If searching for 1st text box then 2nd should keep its value and if searching for 2nd text box 1st should keep its value.

I am using response.redirect method in dg_RowCommand event. I think by this page is rendering with its initial values which is what I don't want.

kindly tell me the solution I have searched so much but came up with nothing.

You can store the values in either Cookie or in a Session variable. Session variable is application specific and cookies are browser specific.

try this, for creating a session variable

Session["key"] = "your value"

or

for Cookie

Response.Cookies["key"].Value ="your value"

on the another page check first is it not null

if(Session["key"]!=null)
// use it

and same for the cookie (access it with Request object)

if (Request.Cookies["key"] != null)
//  use it

use Session variable. Session["YourKey"] = your value; You can access it cross page

Update: If I am right then you are thinking of some wizard type interface. If you can take benefit of ASP.Net Wizard control then look into this. It might help you.

Combine the pages into one, with each page(step) becoming a div or asp:Panel. hide/show divs rather than "navigate to the next page" on Click_Next event (or whatever). This way all controls stay on the same page and maintain all values when the divs are shown/hidden. No Session or other methods needed.

If you are redirecting with the Response.Redirect method in the C# Code then before you execute this redirect you can store the items in Session variables:

Session["Test1"] = test1.Text;

Sessions are maintained per user. These will be retained for as long as the application is running, but be warned that if an Application timeout occurs or the user closes the application (closes browser) these values will be lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM