Access | functions
Effect: For example, a device management system somewhere to fill in the device number, but the device number is usually difficult to remember, and may remember just which department which location of the equipment. Therefore, we want to add a button next to the text box, click to pop a child page, here are the equipment number, equipment details of a table, I just find the device according to the location, double-click this record, the equipment number will be filled up.
Implementation process:
Parent page
The JavaScript function that opens the new window is:
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> called in the button:
<asp:button id= "Button1" runat= "Server" text= "button" onclientclick= "Return openpage (' child.aspx ');" />
Child pages
Binds the data source of the GridView and writes the code in its RowDataBound event as follows:
protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
string s = "window.opener.document.getElementById (' textbox1 '). Value= '" + e.row.cells[1]. Text + "'; Window.close (); ";
if (E.row.rowtype!= datacontrolrowtype.header)
{
E.row.attributes.add ("ondblclick", s);//double-click Select
Set the row color to "" When the mouse is moved, and save the original background color
E.row.attributes.add ("onmouseover", "currentcolor=this.style.backgroundcolor;this.style.backgroundcolor=") C0C0FF '; this.style.cursor= ' hand '; ");
Restores the background color of the row when the mouse is moved
E.row.attributes.add ("onmouseout", "This.style.backgroundcolor=currentcolor");
}
Description: Open a new page through window.open, two pages before there is a parent-child relationship. The child page can access the parent page (the control and the JS function written on the parent page) through opener, and the parent page can also access the child pages through a sub. If there is a JS function SayHello () on the parent page, only Opener.sayhello () can be invoked on the child page.
Using only a few JavaScript code to combine with ASP.net, a very useful effect is accomplished.