An implementation of a common effect (JavaScript's Child parent page access, function call)

Source: Internet
Author: User
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.



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.