1

This is code for Firefox.

Default.aspx:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script type="text/javascript" src="pop.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Hidden1" type="hidden" runat="server" />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Popup" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = "Hello";
        Button1.Attributes.Add("onClick", "javascript:InvokePop('" + TextBox1.ClientID + "');");
    }

PopupWin.aspx:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script type="text/javascript" src="pop.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtValue" runat="server"></asp:TextBox><br />
        <br />
        <input type="button" id="btnReturnValue" value="Return value back" onclick="ReturnValue();" />
    </div>
    </form>
</body>
</html>

pop.js:

function InvokePop(fname)
{
    val = document.getElementById(fname).value;
    retVal = window.open("PopupWin.aspx?Control1=" + fname, 'Show Popup Window', 'height=90,width=250,resizable=yes,modal=yes');
    retVal.focus();
}

function ReturnValue()
{
    var newValue = document.getElementById("txtValue").value;
    if ((window.opener != null) && (!window.opener.closed))
    {
        window.opener.document.getElementById("TextBox2").value = newValue;
    }
    window.close();
}

In this case I click button on Default.aspx page and open Popup.aspx as popup window. I enter some value to text box in Popup.aspx and press button. The new value appears in second text box on Default.aspx page.

That works, but how can I pass the new value entered in Popup.aspx page to some handler in Default.aspx page and use it further? For example, I can have another ASPX button on Default.aspx page and when I click it I can use the value entered in Popup.aspx page.

2 Answers 2

1

Well what you can do is the following:

Add a hiddenField on the first page. Im calling it "hfPopupValue".

In pop.js u are currently doing this:

window.opener.document.getElementById("TextBox2").value = newValue;

You can change this to:

window.opener.document.getElementById("hfPopupValue").value = newValue;

Afterwards you can just read the value from the hiddenField. This should solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you thought of using jQueryUI's Dialog, which lets you keep all controls on the same page, meaning cleaner code.

It also doesn't look as nasty as a JavaScript popup window.

1 Comment

You're right, but I just need this to be solved at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.