Parent.FindControl() 不起作用?

发布于 2024-07-05 19:15:29 字数 201 浏览 9 评论 0原文

我有一个页面有一个 iframe

从 iframe 中的一个页面我想回头看一下并使默认页面上的面板不可见,因为它掩盖了

我尝试使用 Parent.FindControl 但它似乎不起作用的 弹出窗口。 我确信我在 findcontrol 中有正确的 id,因为我使用 Firebug 检查面板,并从那里复制了 id

有谁知道我缺少什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若言繁花未落 2024-07-12 19:15:29

我没有完全理解你的问题,但我会尽力而为。

听起来您有一个 ASP.NET 页面,其中有一个 iframe 引用另一个 ASP.NET 页面,并且在 iframe 请求的该页面中,您想要修改该页面中包含的项目的可见性包含 iframe。

如果我对你的问题的理解是正确的,那么你在这里遇到了一些令人讨厌的问题。

  1. 在浏览器级别实际发生的情况是第一个页面被加载,并且该页面中有一个 iframe 正在向服务器发出第二个请求。
  2. 第二个请求无法 FindControl 您的控件,因为它不在同一页面中,并且在该请求期间不处于活动状态。

因此,您有一些替代方案:

  1. 摆脱 iframe 并使用面板。 这将使它们都处于同一请求中,并且能够找到彼此。
  2. (另外)当您执行此操作时,您将需要使用 Page.FindControl() 而不是 Parent.FindControl(),因为 FindControl 方法只是搜索 Control 的子控件集合,并且我认为您的控件将位于页面上的其他位置。
  3. 在 iframe 的客户端,您可以使用一些 javascript 代码来访问外部页面的 DOM,并在那里设置它的可见性。

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.
獨角戲 2024-07-12 19:15:29

父文档:

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

iframe 中的文档:

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

iframe 内的文档在加载时访问 window 对象 上的 document 对象,并使用 getElementId()函数设置父文档正文中的输入值。

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.

深府石板幽径 2024-07-12 19:15:29

首先,FindControl 不是 Javascript 中的函数。

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

·深蓝 2024-07-12 19:15:29

或者,这里有一个更有用的查找控制例程......

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文