简体   繁体   English

如何移动到下一页然后返回上一页并保留其值ASP.net

[英]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. 我在dg_RowCommand事件中使用response.redirect方法。 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. 您可以将值存储在CookieSession变量中。 Session variable is application specific and cookies are browser specific. 会话变量是特定于应用程序的,并且cookie是特定于浏

try this, for creating a session variable 试试这个,创建一个会话变量

Session["key"] = "your value"

or 要么

for Cookie 用于Cookie

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

on the another page check first is it not null 在另一页检查首先是它不是null

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

and same for the cookie (access it with Request object) 和cookie相同(使用Request对象访问它)

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

use Session variable. 使用Session变量。 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. 如果你可以利用ASP.Net向导控制,那么请看看这个。 It might help you. 它可能对你有帮助。

Combine the pages into one, with each page(step) becoming a div or asp:Panel. 将页面合并为一个,每个页面(步骤)成为div或asp:Panel。 hide/show divs rather than "navigate to the next page" on Click_Next event (or whatever). 在Click_Next事件(或其他)上隐藏/显示div而不是“导航到下一页”。 This way all controls stay on the same page and maintain all values when the divs are shown/hidden. 这样,所有控件都保持在同一页面上,并在显示/隐藏div时保持所有值。 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: 如果使用C#代码中的Response.Redirect方法重定向,则在执行此重定向之前,可以将项存储在Session变量中:

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. 只要应用程序正在运行,这些将保留,但是如果发生应用程序超时或用户关闭应用程序(关闭浏览器),则会警告这些值将丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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