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.