Thursday, June 5, 2014

How to assign value from child to parent pages?

Step-1: Create parent Pages
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!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">
<script src="Scripts/jquery-2.1.0.min.js"></script>
<head runat="server">
   <script language="javascript" type="text/javascript">
       var bankValAgency = "";
       function showSearchAgency() {
           var url = 'test.aspx';
           popup(url, '');
       }
function setAgency( agencyName) {
   debugger;
   var repAgency = String(agencyName);
   $("#<%= this.txtBxAgency.ClientID %>").val(repAgency);
}
       function popup(url, name) {
           var win = window.open(url, name, 'left=400,top=200,height=500,width=600,status=no,resizable=1,scrollbars=1,toolbar=no,location=no,menubar=no');
           win.opener = window;
           if (window.focus) win.focus();
       }
        </script>
</head>
<body>
    <form id="form1" runat="server">
     
<asp:TextBox ID="txtBxAgency" runat="server"  Width="255px" />
<a href="#" onclick=" javascript:showSearchAgency(); ">
<asp:Label ID="lblSelectAgency" Text="Search" runat="server"></asp:Label></a>
<input id="hdnAgencyId" runat="server" name="HdnAgencyId" type="hidden" />
    </form> </body >  </html >

Step-2: Create Child pages

<%@ Page Language="C#"  MasterPageFile="~/Site.Master"  AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApp.test" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
      <script language="javascript" type="text/javascript">
        function setAgency() {
            var instituteName = document.getElementById('txtInstitute').value;
            window.opener.setAgency(instituteName);
            window.close();
            return true;}
    </script>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
  <asp:TextBox ClientIDMode="Static" runat="server" ID="txtInstitute"></asp:TextBox>
  <asp:Button runat="server" ID="btnSubmit" OnClientClick="setAgency();" Text="Submit"/>
</asp:Content>

No comments:

Post a Comment