0

I use showModalDialog function to open popup window, which is ASP.NET page. After I pickup some option in drop down list, I populate window.ReturnValue and press OK button. The modal popup window closes, but I don't know how to pass return value to C# code behind to proceed further.

Here's the code:

Open popup window:

function ClientItemClicked(sender, eventArgs)
{
    if (eventArgs.get_item().get_value() == "excel")
    {
        var retVal = window.showModalDialog("ExportToExcelChoice.aspx", null, "dialogWidth: 400; dialogHeight: 200; center: yes; resizable: no;");
    }
}

Close popup window:

function ReturnValue() {
    var choice = document.getElementById("DropDownList1").value;
    if ((window.opener != null) && (!window.opener.closed)) {
        window.ReturnValue = choice;
        var result = window.ReturnValue;
    }
    window.close();
}

I use Firefox.

2
  • Maybe write it in a hidden field, and read it from there? Commented Feb 15, 2013 at 6:50
  • I've tried it but I don't know how to access hidden field because hidden field is placed inside user control, and user control is inside placeholder, and placeholder is inside content page, and content page is inside master page. I open modal window from inside user control. Do you know how to do that? Commented Feb 15, 2013 at 7:01

1 Answer 1

1

Create server side hidden input and assign the return value to it.

With jQuery:

$("#<%=serverhidden.ClientID%>").val(retVal)

or javascript:

document.getElementById("<%=serverhidden.ClientID%>").value = retVal

Now on postback you can access the value from the hidden input on server side.

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

4 Comments

Yes. I've already tried it, but it doesn't work. Please, take a look at my answer below with the code I use.
This is fourth day how I'm coming here to find the answer, but nobody can help so far.
The hidden field looks as following: <input type="hidden" name="ctl00$ContentPlaceHolder1$ctl00$HiddenField2" id="ctl00_ContentPlaceHolder1_ctl00_HiddenField2" value="0" />
I can use this to make it work: window.opener.document.getElementById("ctl00_ContentPlaceHolder1_ctl00_HiddenField2").value = choice; But, it's not correct way.

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.