ASP. NET parent-child page access

Source: Internet
Author: User
Effect: for example, a device management system must enter a device number somewhere, but the device number is usually hard to remember. What you may remember is the device in which department or location. Therefore, we want to add a button next to the text box and click it to bring up a subpage. Here we have a table that compares the device numbers and device details, I just need to locate the device by location, double-click the record, and enter the device number.

Implementation process:
Parent page

The JavaScript function for opening a new window is:

< Script Type = " Text/JavaScript " Language = " Javascript " >
Function Openpage (htmlurl)
{
VaR Newwin = Window. Open (htmlurl, " Newwin " , " Toolbar = No, location = No, directories = No, status = No, scrollbars = Yes, menubar = No, resizable = Yes, Top = 100, Left = 200, width = 650, height = 300 " );
Newwin. Focus ();
Return   False ;
}

</SCRIPT>

Call in the button:

 

< ASP: button ID = "Button1" Runat = "Server" Text = "Button" Onclientclick = "Return openpage ('child. aspx ');" />

The child page binds the data source of the gridview and writes it in its rowdatabound eventCodeAs follows:

 

Protected   Void Gridview1_rowdatabound ( Object Sender, gridviewroweventargs E)
{
String S =   " Optional values opener.doc ument. getelementbyid ('txbrolename'). value =' "   + E. Row. cells [ 1 ]. Text +   " '; " +
" Optional values opener.doc ument. getelementbyid ('txbroleid'). value =' "   + E. Row. cells [ 0 ]. Text +   " '; "  
+ " Window. Close (); " ;
If (E. Row. rowtype ! = Datacontrolrowtype. header)
{
E. Row. Attributes. Add (
" Ondblclick " , S ); // Double-click
// When the mouse moves, set the line color to "" and save the original background color.
E. Row. Attributes. Add ( " Onmouseover " , " Currentcolor = This. style. backgroundcolor; this. style. backgroundcolor = '# c0c0ff'; this. style. cursor = 'hand '; " );
// Restore the background color of the row when the mouse moves
E. Row. Attributes. Add ( " Onmouseout " , " This. style. backgroundcolor = currentcolor " );
}
}

 

Note: A New Page is opened through window. Open, and a parent-child relationship exists before the two pages. The child page can access the parent page through opener (controls and JS functions written in the parent page), and the parent page can access the child page through sub in the same sample. For example, if there is a JS function sayhello () on the parent page, you only need opener. sayhello () on the subpage to call it.

The combination of a few JavaScript code and Asp.net completes a very useful effect.

 

From: http://www.cnblogs.com/jeffamy/archive/2006/05/11/396880.html

 

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.