Sunday, January 11, 2009

Javascript : From Child to Parent

Passing data between Popup to Parent window is easy once you are aware of the
method window.opener method

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="popup.aspx.vb" Inherits="WebApplication10.popup" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">
        function alertParent() {
            var divparent = window.opener.document.getElementById("fromchild");
            var chidmsg = document.getElementById("toparent");
            divparent.innerText = chidmsg.value;
            window.close();
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="toparent" type="text" />
        <input id="Button1" type="button" value="Respond to Parent" onclick="alertParent();" />
    </div>
    <hr />
    Parent said : <span id="fromparent"></span>
    </form>
</body>
</html>

No comments:

Post a Comment