FindControl不起作用 [英] FindControl doesn't work
问题描述
我正在尝试使用FindCrontrol,但它无法正常工作。以下是代码:
Dim DisplayPanel As Panel
DisplayPanel = CType(FindControl(" pnlName"),Panel)
>
无论我怎么做 - 我都试过Me.FindControl,Page.FindControl,
只是简单的FindControl,DisplayPanel变量总是没有什么
代码执行后。该面板确实存在,名称为pnlName
,我可以在代码中使用它。如果我打破代码,为面板提供的父母
是Content1,但我不能在代码中引用
Content1。 />
我尝试过不同类型的其他控件,每次都得到同样的东西
。我错过了什么?
Dim c As System.Web.UI.Control
Dim ctlToFind作为小组
c = Me.Parent
虽然ctlToFind什么都没有
ctlToFind = CType(c.FindControl(" pnlName"),Panel)
c = c.Parent
结束时
FindControl仅适用于内部的立即控件Coontrol。控件
嵌套在其他控件中,所以你需要使用递归来找到
控件,如果你不知道它内部的确切控件。 />
-
HTH,
Kevin Spencer
Microsoft MVP
鸡肉沙拉手术
橘子你平淡无奇我停止了香蕉蔓延?
丹尼斯 < db ******** @ gmail.comwrote in message
news:11 ********************* @ m79g2000cwm.googlegro ups.com ...
我正在尝试使用FindCrontrol,但它不起作用。以下是代码:
Dim DisplayPanel As Panel
DisplayPanel = CType(FindControl(" pnlName"),Panel)
>
无论我怎么做 - 我都试过Me.FindControl,Page.FindControl,
只是简单的FindControl,DisplayPanel变量总是没有什么
代码执行后。该面板确实存在,名称为pnlName
,我可以在代码中使用它。如果我打破代码,为面板提供的父母
是Content1,但我不能在代码中引用
Content1。 />
我尝试过不同类型的其他控件,每次都得到同样的东西
。我缺少什么?
fa *******@gmail.com 写道:
Dim c As System.Web.UI.Control
Dim ctlToFind作为面板
c = Me.Parent
虽然ctlToFind什么都没有
ctlToFind = CType(c.FindControl(" pnlName")) ,小组)
c = c.Parent
结束时
谢谢,但那不起作用因为Me.Parent什么都没有。这是在page_load事件的
中,面板在页面本身,不包含
在另一个控件中,如果这有所不同。
>
I''m trying to use FindCrontrol and it will not work. Here is the code:
Dim DisplayPanel As Panel
DisplayPanel = CType(FindControl("pnlName"), Panel)
No matter how I do it - I''ve tried Me.FindControl, Page.FindControl,
just plain FindControl the DisplayPanel variable is always Nothing
after the code execute. The panel does exist with the name "pnlName"
and I can use that just fine in code. If I break the code, the Parent
that is given for the panel is "Content1", but I can''t reference
Content1 in the code.
I''ve tried other controls of different types and I get the same thing
every time. What am I missing?
Dim c As System.Web.UI.Control
Dim ctlToFind As Panel
c = Me.Parent
While ctlToFind Is Nothing
ctlToFind = CType(c.FindControl("pnlName"), Panel)
c = c.Parent
End While
FindControl only works on the immediate Controls inside a Coontrol. Controls
are nested inside other Controls, so you need to use recursion to find the
Control if you don''t know the exact Control it is immediately inside.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
Orange you bland I stopped splaying bananas?
"Dennis" <db********@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...I''m trying to use FindCrontrol and it will not work. Here is the code:
Dim DisplayPanel As Panel
DisplayPanel = CType(FindControl("pnlName"), Panel)
No matter how I do it - I''ve tried Me.FindControl, Page.FindControl,
just plain FindControl the DisplayPanel variable is always Nothing
after the code execute. The panel does exist with the name "pnlName"
and I can use that just fine in code. If I break the code, the Parent
that is given for the panel is "Content1", but I can''t reference
Content1 in the code.
I''ve tried other controls of different types and I get the same thing
every time. What am I missing?
fa*******@gmail.com wrote:Dim c As System.Web.UI.Control
Dim ctlToFind As Panel
c = Me.Parent
While ctlToFind Is Nothing
ctlToFind = CType(c.FindControl("pnlName"), Panel)
c = c.Parent
End While
Thanks, but that doesn''t work because Me.Parent is nothing. This is in
the page_load event and the panel is on the page itself, not contained
in another control, if that makes a difference.
这篇关于FindControl不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!