1

I am using a user control and I need to call a popup, which asks a question, and I need to send the response (true or false) back to the user control that invokes the popup. I declared a hidden field to store the value in it from client-side so I can have access to it from the code behind and then execute further code. I have the following code:

ASP.Net

<script type="text/javascript">
        function confirmNoCallList() {
            debugger;
            var resp = confirm("¿Seguro/a que desea agregar a este subscriptor a la 
                       lista de 'No Llamar'?");

            window.opener.document.getElementById('hfAddToNoCallList').value = resp;
        }
</script>


<ajax:TabContainer ID="tbcMyProfile" runat="server" ActiveTabIndex="0" Width="500px">
        <ajax:TabPanel ID="tbpInfoCta" runat="server" HeaderText="Información de mi
                           Cuenta">
            <ContentTemplate>
                <asp:HiddenField ID="hfAddToNoCallList" runat="server" />
.
.
.

I am getting an error when the function hits the window.opener line. Any ideas on how to do this the right way?

0

2 Answers 2

1

You have to get the dynamic ClientID at runtime or pass it to a function and an arg that can then find it:

document.getElementById('<%= hfAddToNoCallList.ClientID"%>').value = resp;

or

   function confirmNoCallList(hiddenField) {
        debugger;
        var resp = confirm("¿Seguro/a que desea agregar a este subscriptor a la 
                   lista de 'No Llamar'?");

        document.getElementById(hiddenField).value = resp;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! both ways are exactly what I was looking for.
1

window.opener gives you a reference to the browser window that called window.open(...) to create the current window. If you're not calling window.open then opener will be null.

In the code snippet you've posted, the JavaScript and hidden field are in the same document. Try removing window.opener. from the line window.opener.document.getElementById ...

1 Comment

I get the following error if I do that: Unable to set value of the property 'value': object is null or undefined

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.