Nov 16, 2011

How to Send value return from child form/page to parent form/page via window.open() in java script

------------------------------------------In Default4.aspx------------------------------------------------

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="YourTextBox" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="open" OnClientClick="openPopup();" /></div>
    </form>
</body>


<script type="text/javascript">
<!--
function openPopup()
{
 var elementId = '<%= YourTextBox.ClientID %>';
 var windowUrl = 'PopupPage.aspx?ElementId=' + elementId;
 var windowId = 'NewWindow_' + new Date().getTime();
 var windowFeatures =
  'channelmode=no,directories=no,fullscreen=no,' +
  'location=no,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' +
  'status=no,toolbar=no,titlebar=no,' +
  'left=0,top=0,width=400px,height=200px';
 var windowReference = window.open(windowUrl, windowId, windowFeatures);
 windowReference.focus();

}
// -->
</script>
</html>
------------------------------------------------------------------------------------------------


------------------------------------------PopupPage.aspx----------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" OnClientClick="closeWindow();" Text="Close" /></div>
    </form>
</body>



<script type="text/javascript">
<!--
function closeWindow()
{
 // C#
  window.opener.document.getElementById('<%= Request["ElementId"] %>').value = 'Some new value';


 window.opener.focus();
 window.close();
}
// -->
</script>
</html>
-------------------------------------------------------------------------------------------------

No comments:

Post a Comment

What is the use of n-tier architecture and 3-tier architecture?

how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...