How to save page status between infinite jumps on a page (1)

Source: Internet
Author: User
Tags filter modify requires sort
Page intro
This is a very difficult topic, just describe it, will be very difficult, but I try, I hope to describe clearly:

Our company is using List/detail page logic, that is, the list page has a DataGrid, listed some items, click on one of the items, the page jumps to the detail page to view the details of the item. The Detail page has a return button that is returned to the list page when clicked. The list of data is usually filtered, such as xxx greater than 20, and then sorted.

Now the question is this:

User requirements, when returned from detail to the list, the status in the list of data is unchanged.

The Company believes that this is a reasonable request, because the amount of data is too large, who do not want to return to the list and from the first page to look.

Also requires that the detail item you just read must be on the current page of the list of data, not necessarily the page in the list of previous lists, but if you delete the current item in detail, the return must be on the page that goes to the list of previous list data.

Even more troubling, when detail pages, the user may jump to several related pages, which may also have Datadrid, and then the user will be able to jump into the corresponding detail page where the corresponding states will also be maintained.

It is also possible that there will be multiple DataGrid in a list page.

Let's take an example:

The user looks at the DATAGRID_A1 and Datagrid_a2 in the A_list,a_list, where the data is filtered, and then he looks at the item A1.1 the data, which goes into a1.1_detail, and then jumps into A1.1 's related pages a1.1_ DETAIL2, this page has a datagrid_a1.1, he is filtering, sorting, and then jumps into another related page of A1.1, this page is a List page a1.1_list, which has a datagrid_ A1.11, it is clear that the data on this page is also filtered, the user to order him, and then into one of the detail page A1.11.1, modify the data ...

Well, after doing these, he returned. Go back to the a1.1_list, ask for datagrid_a1.11 filter conditions, sort the same way, the one you just visited on the DataGrid on the current page, before the item may be on the second page, now may be on page fourth, then show page fourth; then go back to A1.1_ Detail2, the datagrid_a1.1 filter, sort, current page number on this page, return to A1.1_detail, delete the A1.1 data, and then return to A_list, which requires the filter criteria for the two DataGrid on the page, The sort method is unchanged, showing the page number that preceded it.

What's even more frightening is that the real user does not necessarily have the same way back, so you don't want these page state data to follow the LIFO principle.

What should I do?

The reason for this problem arises
If you are in a Windows program, this is very simple, because from the first, a record of the detail and its related information, usually a form of multiple tabs, even if it is to open another form, but also the hide (hidden) up, and then show it back. In the final analysis, the Windows program is a stateful application, and everything is simple.

To the web is not the same, the web is stateless, every time the page back, do not know their own a variable before what value, let alone between the page, each page, do not know where they from (which page).

Problem analysis
Such a difficult problem, look dizzy, but to solve the problem, still have to use a sober brain to think about the problem.

Basic idea: Save the state data of the previous page, and jump to a new page, the page saves the state data of the previous page, and then when you return, the page will retrieve the original data.



Let's take a look at what to do with the data exchanged between pages.

In general, the URL parameter is the way, but obviously lost the utility here, the URL has a length limit, and so many parameters, the assembly URL string will cause you a headache dead.

How to do it, had to use a different way:

When you jump from a page, do not use Response.Redirect, but apply Server.Transfer, and then use Context.Handler in the target page, as follows:

The class of the previous Web page is ABC, and the last page is dbc.aspx,

Define a public field in the previous page ABC

public string CCC;

So when you jump in ABC, you use

Server.Transfer (dbc.aspx)

Use in the latter page

((ABC) context.handler). CCC can take out the corresponding value.



But there is clearly a problem with the lack of versatility. How to do multiple page jumps? and the Context.Handler.GetType () method is unusable and an exception occurs.

Then define the interface.

The data about the need for mutual transmission is defined in the interface, and multiple Web pages implement the same interface.

Query parameters, sort criteria, the current page to display, the project ID to display on the current page ... are defined in the implementation of the interface.



But the problem is, the page in the jump, the data will accumulate, such as you jump from List1 to Detail1, and then jump to List2, and then jump to Detail2, this time Detail2 to save the previous three pages of data, and these three pages to achieve the same interface, This can result in data overwrite situations.

In general, in the face of this situation is the design of a stack-like data structure, each entry to a new page, the original page of the data into the stack, which is called the protection of the scene.

Unfortunately, this also can not be used, because the user does not necessarily will return the original way, if the first out of the way, you will find a Web page to retrieve their own data but found that can not get back, to fetch is not their own data.

You can only use arrays, and the array is dynamic.

Then modify the interface just now, change it into a class datainfo, and then implement an interface with a dynamic array to store the Datainfo.



But the elements of a dynamic array are object, the scope is too wide, I want to be strict, only allow storage rather than disorderly heap in the array, if really in the interface to implement a dynamic array, then you go inside Datainfo, I plug in other things, it is not a mess.

Then wrap the dynamic array outside so that it only allows storage of datainfo. Can not be directly wrapped in the interface, because I would like to add some code to check whether the store is just datainfo, or something else. What to do, then customize a class datainfolist. And these classes are marked as serializable, serializable so that the state can be saved in viewstate.



(To be continued)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.