views:

2669

answers:

6

I have a page that has an iframe

From one of the pages within the iframe I want to look back and make a panel on the default page invisible because it is overshadowing a popup

I tried using Parent.FindControl but it does not seem to be working. I am positive I have the right id in the findcontrol because I used Firebug to inspect the panel and I copied the id from there

Does anyone know what I am missing?

A: 

For starters, FindControl isn't a function in Javascript.

troelskn
that is because I was using in the code behind
jmein
A: 

@troeskn

I know it isnt my button that causes the popup to pop is in a gridview and when it pops it also has to do several other things on the server so I used an OnRowCommand which has worked perfectly

In the OnRowCommand I then added the Parent.FindControl and tried to find the Panel object and set its visibility to false but it does not seem to be working

jmein
ah .. you're using server side JScript -- which is something entirely different from Javascript, that runs at the client side.
troelskn
I wasnt the one that put the Javascript tag on there it was someone else
jmein
+3  A: 

I didn't completely follow your problem, but I'll take my best shot.

It sounds like you have an ASP.NET page, that has an iframe in it that refers to another ASP.NET page, and in that page that was requested by the iframe you want to modify the visibility of the item contained in the page that contains the iframe.

If my understanding of your problem is correct, then you have some somewhat nasty problems here.

  1. What's actually happening at the browser level is the first page gets loaded, and that page has an iframe in it that is making a second request to the server.
  2. This second request can't FindControl your control, because it isn't in the same page, and isn't alive during that request.

So you have some alternatives here:

  1. Get rid of the iframe and use a panel. This will put them both in the same request, and able to find each other.
  2. (Additionally) When you do this you are going to want to use Page.FindControl() not Parent.FindControl() as the FindControl method just searches through the Control's child control collection, and I presume your control will be somewhere else on the page.
  3. On the client side in the iframe you could use some javascript code to access the outer page's DOM, and set the visibility of it there.
jhuffaker
+2  A: 

Parent document:

<body>
    <input type="text" id="accessme" value="Not Accessed" />
    ...
</body>

Document in iframe:

<head>
    ...
    <script type="text/javascript">
        function setValueOfAccessme()
        {
            window.parent.document.getElementById("accessme").value = "Accessed";
        }
    </script>
</head>
<body onload="setValueOfAccessme();">
</body>

The document inside the iframe accesses the document object on the window object on load, and uses the getElementId() function to set the value of the input inside the body of the parent document.

roosteronacid
A: 

Alternatively here's a more helpful find control routine...

Public Shared Function MoreHelpfulFindControl(ByVal parent As UI.Control, ByVal id As String) As UI.Control
    If parent.ID = id Then Return parent
    For Each child As UI.Control In parent.Controls
        Dim recurse As UI.Control = MoreHelpfulFindControl(child, id)
        If recurse IsNot Nothing Then Return recurse
    Next
    Return Nothing
End Function
Sean Gough
A: 

ok I am going to further explain my page and what is going on so that everyone can understand a little better

I have a default page. This page contains an iframe which contains a tab interface with each tab loading a control page From one of these control pages I need to hide a panel on the default page because it overshadows a popup

Does this make sense or should I explain it more

jmein