Solution for retaining the original result of the last return result after page Jump

Source: Internet
Author: User

From February to work for a new company, the task started was to familiarize yourself with the projects that the company has been working on. In addition, modifying some inconvenient operations in the original project is to improve the user experience.

One of the tasks is to solve the problem returned by the page. At first they all use the Goback (); method. According to the project design, each function jumps to a new page (not open in a new window ).

In this way, we will have a bad experience. For example, when I enter a page and select n multiple query conditions, a result list is displayed. When I click the specific information, a detailed information page (non-new window) is displayed ), on this details page, I modify the information. The operation is completed at this time. Return to the result list page. Click the button twice. In this way, the operator will feel very troublesome. Therefore, we recommend that you do not use the method currently used by our project. Any new function will jump to a new page.

Recommended Methods

1: on the same page, the tool function shows and hides different panl. Data passing between pages is not involved

2: open in a new window

3: Use the pop-up layer

4: View status

5: Post Data to the details page,And then post back when the detailed page is returned, but this does not conform toSp.net

However, it is impossible for my project to be greatly changed. I can only change it based on the original one. There are many ways to change

1: Session, not recommended, will affectProgramPerformance

2: URL parameter: insecure because the parameter is exposed.

3: obtained through httpcontext. Current. Handler

Appendix 1CodeFor everyone to understand

 

Code
Public   Partial   Class Serach: system. Web. UI. Page
{
Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
Result result;
If (Httpcontext. Current. Handler Is Result)
{
Result=Httpcontext. Current. HandlerAsResult;
Response. Write (result. Text );
}
}
}

Public   String Datatime
{
Get   {Return This. Textbox1.text ;}
Set   {This. Textbox1.text=Value ;}
}

Protected   Void Button#click ( Object Sender, eventargs E)
{
Server. Transfer ("Result. aspx");
}
}
// Query page

 

 

Public   Partial   Class Result: system. Web. UI. Page
{

Protected   Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
Serach;
If (Httpcontext. Current. Handler Is Serach)
{
Serach=Httpcontext. Current. HandlerAsSerach;
This. Hiddenfield1.value=Serach. datatime;
}
}
}

Public   String Text
{
Get   {Return This. Hiddenfield1.value ;}
Set   {This. Hiddenfield1.value=Value ;}
}
Protected   Void Btntext_click ( Object Sender, eventargs E)
{
Server. Transfer ("Serach. aspx");
}
}

// Result page

 

In this way, you can save your initial query SQL statement and re-load the SQL statement when returning it.

 

4: Server.Transfer works with previouspage attributes

The page class has a previouspage attribute, so that you can obtain the information of the previous page.

 

If (Page. previouspage ! =   Null )
{
Contentplaceholder content = (Contentplaceholder) page. previouspage. master. findcontrol ( " Uicontentareaplaceholder " );
// Response. Write (HF. value );
If (Content ! =   Null )
{
Hiddenfield HF = (Hiddenfield) content. findcontrol ( " Hfsql " );
If (HF ! =   Null )
{
This . Hfsql. Value = HF. value;
// How to load SQL statements by myself
Loaddata‑gridview ();
}
}
}

 

You can store the information you want to save in a hiddenfield. Then use server.When the transfer jumps to another page, you can use the previouspage property to find the control for saving information on the previous page.

This method is used this time.

I would like to thank the MVP lovecherry in the garden.

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.