The response. Redirect method in Asp.net is displayed in the new window.

Source: Internet
Author: User
1. Purpose:
The page contains a buttn named btnnew. It will pop up a page for new content.
The page contains a gridview used to display data. The last two columns of the gridview are "detail" and "delete ".
Btnnew is required to pop up a new window for adding data.
A new window is displayed in the "details" column of gidview to view data.
The delete column in gidview is used to delete the data of the current row.
Now the problem is coming.
Problem 1: The response. Redirect method cannot open a new window.
Question 2: If the target = '_ blank' attribute in form is used, a new window is displayed when you click Delete in the gridview.
Question 3: If you change "delete" to <a href = 'xxx. aspx 'target = '_ blank'> Delete </a>. Unable to call future generations Code Unless Ajax is used.

Problem 4: Use the JS window. open () method. When "window. opener. Location. href = Window. opener. Location. href" is used to refresh the parent window, the data in the gridview cannot be refreshed. When "window. opener. location. reload (); "when refreshing the parent window, each refresh will pop up a dialog box for sending a message again, asking you to confirm and resend the message to refresh the page (the latter method was tested by netizens ).

2. solution:
1、when you single-click btnnewexample, let form.tar get = '_ blank', so that all links will open in a new window.

2XX When deleting a single statement, let form.tar get = '_ Self' first '. In this way, no new window will pop up.

 

3. The Code is as follows:

1) single-click btnnewto make form.tar get = '_ blank '. This method is put in the load event.

Protected   Void Page_load ( Object Sender, eventargs E)
{
Try
{
If ( ! Ispostback)
{
Btnnew. Attributes. Add ( " Onclick " , " Form.tar get = '_ blank' " );
}
}
Catch (Exception error)
{
}
}

2nd, before deleting, let the form.tar get = '_ Self' code first: this event is placed in the rowdatabound event of the gridview. Code:

Protected   Void Gvwlist_rowdatabound ( Object Sender, gridviewroweventargs E)
{
// Hide key
E. Row. cells [ 0 ]. Visible =   False ;
// The pop-up window is not displayed, and Deletion prompt.
E. Row. cells [E. Row. cells. Count -   1 ]. Attributes [ " Onclick " ] =   " Document.forms1_02.16.tar get = '_ Self'; return confirm ('Are you sure you want to delete it? '); " ;
}

 

 

 

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.