The ASP. Net query page sets the form action attribute to only pop up one page, and each time the page is set to the beginning

Source: Internet
Author: User

Background

When the data volume is large and the query conditions are complex and varied, we may need to make a separate query interface. When you select to set the relevant query conditions, click the [query] button, A new page is displayed, showing the dataset queried Based on the condition.

Then, each time you click the [query] button, a new page is displayed to display the latest query results.

Of course, in a good user experience, I think that no matter how many times a user clicks the [query] button, the system should only pop up and have only one page, this page displays the query results. This page should also be displayed at the beginning of the window. If you use a tab browser, the system will prompt you that the current query result has been updated to the latest in the form of flashing.

 

Solution

 

As you know, setting form actions directly in Asp.net is ineffective, or some unexpected events may occur when PostBack is generated. For example:

<FormID= "Form1"Runat= "Server"Action= "Searchresult. aspx" >

 

Now, we can only dynamically set the action and target attributes of form through JavaScript, as shown below:Code:

 Function  Formsubmit (){
VaR Action = $ ( ' # Form1 ' ). ATTR ( ' Action ' );
VaR Target = $ ( ' # Form1 ' ). ATTR ( ' Target ' );
$ ( ' # Form1 ' ). ATTR ( ' Action ' , ' Retireeinfosearchresult. aspx ' );
$ ( ' # Form1 ' ). ATTR ( ' Target ' , ' Retireeinfosearchresult. aspx ' );
VaR D = $ ( ' # Form1 ' ). Submit ();
// Alert (d );
$ ( ' # Form1 ' ). ATTR ( ' Action ' , Action );
$ ( ' # Form1 ' ). ATTR ( ' Target ' , Target );
Return False ;
}

 

When you click the query button, the formsubmit method is triggered. The formsubmit method is used to save the form attributes, and then the form action and target attributes are set, set target to the page path of the query result, so that only one page is displayed, rather than multiple pages can be saved. After the final form is submitted, restore the form attributes.

 

Make sure that the query result is displayed at the beginning or prompt the user

On the query result page, add an onload event to the body as follows:

 
<BodyOnload= "Self. Focus ();">

This ensures that the focus is on the query result page when the page is loaded.

 

Related Article

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.