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