About page Jump finally return to the original page to maintain the original results of the approach

Source: Internet
Author: User
Tags httpcontext

February to the new company to work, the beginning of the task is familiar with the company has been doing projects. and modify the original project in some of the inconvenient operation, is to improve the user experience.

One of the tasks is to solve the problem of page return, starting with all the GoBack () methods. According to the design of the project, each function is to jump to a new page (not open in a new window).

This will have a very bad experience when used at last. For example, I entered a page, select the N multiple query conditions, there will be a result list, point specific information, will jump to a detailed information page (not a new window), I in this detail page for information modification. This is the time to complete the operation. You need to return to the results list page. You need to click the button 2 times. So the operator will find it troublesome. So I suggest not to use this method of our project now, any new features will jump to a new page.

Recommend several methods

1: On the same page, tool function, show and hide different panl. Does not involve passing values between pages

2: Open in New window

3: Use the pop-up layer

4: View state

5:post the data to the Detail page, and then post it back when the detail page points back, but that doesn't fit the asp.net.

But my project can not be changed greatly, can only be changed on the basis of the original. There are many ways to change

1:session, not recommended, can affect program performance

2:url parameter: Unsafe because the parameter is exposed to the outside side

3: Through the HttpContext.Current.Handler to obtain

Attach a small piece of code to let you understand

public partial class Serach:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (!             IsPostBack)
{
result result;
if (HttpContext.Current.Handler)
{
result = HttpContext.Current.Handler as result;
Response.Write (Result.text);
}
}
}

public string datatime
{
Get {return this. TextBox1.Text; The
set {this. TextBox1.Text = value;
}

protected void Button1_Click (object sender, EventArgs e)
{
Server.Transfer ( "Result.aspx");
}

//Query page

public partial class Result:System.Web.UI.Page
{

protected void Pa Ge_load (object sender, EventArgs e)
{
if (!             IsPostBack)
{
Serach serach;
if (HttpContext.Current.Handler is Serach)
{
Serach = HttpContext.Current.Handler as serach;< br> this. Hiddenfield1.value=serach.datatime;
}
}
}

public string text
{
. Hiddenfield1.value; The
set {this. Hiddenfield1.value = Value;
}
protected void Btntext_click (object sender, EventArgs e)
{
Server.Transfer ("Ser Ach.aspx ");
}
}

//Results page

So you can save your initial query SQL statements, and then reload the SQL statements when you return.

4:server.transfer with PreviousPage Properties

The page class has a PreviousPage property so you can get the information from the last 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;
              //本人加载SQL语句的方法
              LoadDataIntoGridView();
            }
       }
  }

You can save the information you want to save in a HiddenField. Then use the Server.Transfer to jump to another page when you can find the last page to save the information through the PreviousPage property control to get

That's the way I use it this time.

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.