Click here to Skip to main content
15,922,650 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a javascript function in which if a user select future date then a pop up will appear and that pop up will contain an text box and a button.The user enter the value in the text box and click on the Button of child pop up.I want to capture those value in the parent window but i m not able to do it.

Below is the javascript which i had written:-
JavaScript
function CheckDateEalier(sender, args)
         {
            var toDate = new Date();
            toDate.setMinutes(0);
            toDate.setSeconds(0);
            toDate.setHours(0);
            toDate.setMilliseconds(0);
            if (sender._selectedDate < toDate)
             {
                alert("You can't select day earlier than today! In Case if you are selecting Previous date then, By default it will take current Date.");
                sender._selectedDate = toDate;
                //set the date back to the current date
                sender._textbox.set_Value(sender._selectedDate.format(sender._format))
            }
            if (sender._selectedDate > toDate) {
                var timeSpent = window.open("EnterTimeSpent.aspx", "List", "scrollbars=no,resizable=no,width=320,height=100");
                document.getElementById('<%=hiddenFieldFutureDateSelectTimeSpent.ClientID %>').value = timeSpent;
                return false;

            }
        }

ASP Code for Child page:-
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EnterTimeSpent.aspx.cs" Inherits="EmployeeQuotient.EnterTimeSpent" %>
<!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">
    <link href="CSS/buttons.css" rel="stylesheet" type="text/css" />
    <title>Enter Time Spent</title>
</head>
<body>
<script language="javascript" type="text/javascript">
 
</script>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
        <asp:Label ID="Label1" runat="server" Text="Time Spent : " Font-Bold="True" 
            Font-Italic="False" Font-Names="Times New Roman" Font-Size="Small" 
            ForeColor="green"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="txtTimeSpent" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTimeSpent" ErrorMessage="Field Cant be left blank." Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator><br />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"  ControlToValidate="txtTimeSpent" ValidationExpression="^\d+$" ErrorMessage="Only Numeric with non decimal allowed"  Font-Size="X-Small" ForeColor="Red"></asp:RegularExpressionValidator></td>
    </tr>
    <tr>
    <td>
        <asp:Button ID="btnSubmitTimeSpent" runat="server" Text="Submit" CssClass="button small green rounded" OnClientClick="btnSubmitTimeSpent()"/></td></tr>
    </table>    
    </div>
    </form>
</body>
</html>

Please help me that how i pass those value from child to parent from javascript and page will close as user click on the button, currently when i m clicking on button again a modal pop up is appearing and then i have to manually close the page.
Posted

hi,
add a TextBox on your parent page as

ASP.NET
<asp:textbox id="Txtparent" runat="Server" xmlns:asp="#unknown" />

and set its value from the child page as

JavaScript
window.opener.document.forms[0].getElementById('Txtparent').value ="Value From Popup Page";
 
Share this answer
 
You can also return the value on button click

JavaScript
function btnSubmitTimeSpent()
{
window.returnValue="time";
window.close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900