FindControl无法正常工作 [英] FindControl not working

查看:68
本文介绍了FindControl无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我做错了什么。这是我的代码:


受保护的子页面_Load(ByVal发送者作为对象,ByVal e As System.EventArgs)

处理Me.Load


Dim hyp As HyperLink = CType(Me.FindControl(" hypFilt"&

Request.QueryString(" Filt")),HyperLink)

如果不是什么就没有呢

hyp.Font.Bold = True

EndIf


结束如果


我在页面上有几个超链接控件。有些是ID = hypFiltA,

hypFiltB,hypFiltC等。它们用于按字母表的第一个字母

过滤一些数据。代码运行,没有崩溃,但上面的代码永远不会发现它们。 hyp always = nothing。


" hypFilt" &安培; Request.QueryString(" Filt")确实评估了正确的

值。


谢谢,


Keith

I''m not sure what I''m doing wrong. Here''s my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim hyp As HyperLink = CType(Me.FindControl("hypFilt" &
Request.QueryString("Filt")), HyperLink)
If Not hyp Is Nothing Then
hyp.Font.Bold = True
EndIf

End If

I have several hyperlink controls on a page. Some are ID = hypFiltA,
hypFiltB, hypFiltC, etc. They are used to filter some data by first letter
of the alphabet. The code runs, nothing crashes but but the code above never
finds them. hyp always = nothing.

"hypFilt" & Request.QueryString("Filt") does evaluate out to the correct
value.

Thanks,

Keith

推荐答案

我应该提到超链接控件没有嵌入到另一个

控件中。它们位于内容部分,但当我输入me.hyp ...时,它们被

intellisense识别。进入vb代码页。


" Keith G Hicks" < kr*@comcast.netwrote in message

news:uF ************** @ TK2MSFTNGP05.phx.gbl ...
I should mention that the hyperlink controls are not embeded inside another
control. They are in a content section but they are recognized by
intellisense when I type "me.hyp..." into the vb code page.

"Keith G Hicks" <kr*@comcast.netwrote in message
news:uF**************@TK2MSFTNGP05.phx.gbl...

我不确定我做错了什么。这是我的代码:


受保护的子Page_Load(ByVal发送者为对象,ByVal e为
I''m not sure what I''m doing wrong. Here''s my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As



System.EventArgs )

System.EventArgs)


Handles Me.Load


Dim hyp As HyperLink = CType(Me.FindControl(" hypFilt"&)&

Request.QueryString(" Filt")),HyperLink)

如果不是什么就没有了呢

hyp.Font.Bold = True

EndIf


结束如果


我在页面上有几个超链接控件。有些是ID = hypFiltA,

hypFiltB,hypFiltC等。它们用于按字母表的第一个字母

过滤一些数据。代码运行,没有崩溃但是上面的代码是
Handles Me.Load

Dim hyp As HyperLink = CType(Me.FindControl("hypFilt" &
Request.QueryString("Filt")), HyperLink)
If Not hyp Is Nothing Then
hyp.Font.Bold = True
EndIf

End If

I have several hyperlink controls on a page. Some are ID = hypFiltA,
hypFiltB, hypFiltC, etc. They are used to filter some data by first letter
of the alphabet. The code runs, nothing crashes but but the code above



从不

never


找到它们。 hyp always = nothing。


" hypFilt" &安培; Request.QueryString(" Filt")确实评估了正确的

值。


谢谢,


Keith

finds them. hyp always = nothing.

"hypFilt" & Request.QueryString("Filt") does evaluate out to the correct
value.

Thanks,

Keith



设置断点并查看id是否正确形成,运行Me.FindControl

在观察窗口中,查看Me.Controls集合中的内容。这个

应该可以帮助你弄清楚发生了什么。


-

Eliyahu Goldin,

软件开发人员

Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http:// usefulasp .net

" Keith G Hicks" < kr*@comcast.netwrote in message

news:uF ************** @ TK2MSFTNGP05.phx.gbl ...
Set a breakpoint and see if the id is formed correctly, run Me.FindControl
in the watch window, see what is inside the Me.Controls collection. This
should help you to figure out what is going on.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Keith G Hicks" <kr*@comcast.netwrote in message
news:uF**************@TK2MSFTNGP05.phx.gbl...

我不确定我做错了什么。这是我的代码:


受保护的子Page_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)

Handles Me.Load


Dim hyp As HyperLink = CType(Me.FindControl(" hypFilt"&

Request.QueryString(" Filt" )),HyperLink)

如果不是什么不是那么

hyp.Font.Bold = True

EndIf

结束如果


我在页面上有几个超链接控件。有些是ID = hypFiltA,

hypFiltB,hypFiltC等。它们用于按字母表的第一个字母

过滤一些数据。代码运行,没有崩溃,但上面的代码

从来没有

找到它们。 hyp always = nothing。


" hypFilt" &安培; Request.QueryString(" Filt")确实评估了正确的

值。


谢谢,


基思

I''m not sure what I''m doing wrong. Here''s my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load

Dim hyp As HyperLink = CType(Me.FindControl("hypFilt" &
Request.QueryString("Filt")), HyperLink)
If Not hyp Is Nothing Then
hyp.Font.Bold = True
EndIf

End If

I have several hyperlink controls on a page. Some are ID = hypFiltA,
hypFiltB, hypFiltC, etc. They are used to filter some data by first letter
of the alphabet. The code runs, nothing crashes but but the code above
never
finds them. hyp always = nothing.

"hypFilt" & Request.QueryString("Filt") does evaluate out to the correct
value.

Thanks,

Keith



似乎ID很好。当我把me.hypFiltA,或者me.hypFiltB等等手表中的
时,他们给了我一个值。

Request.QueryString(" Filt")中的观察窗口返回我期望的内容:A

或B或C或C。等等


当我把我。控制在观察窗口时,我得到的数量为1.


当我放入Me.FindControl时(hypFilt& Request.QueryString(" Filt"))在

观察窗口中,它显示为Nothing。


如果我硬编码me.hypFiltA在同一个事件处理程序中,它工作正常。

控件存在,我可以设置其属性。但我不想将所有26个字母的字母编码到事件处理程序中。


我在其他页面事件中也试过这个( preload,init,initcomplete,

loadcomplete,prerender,prerendercomplete ...都有相同的结果。

Eliyahu Goldin"< RE ******* *******************@mMvVpPsS.org写在

消息新闻:eX ************** @ TK2MSFTNGP06.phx.gbl ...
It seems that the ID''s are fine. When I put me.hypFiltA, or me.hypFiltB, etc
in the watch, they give me a value.
Request.QueryString("Filt") in the watch window returns what I expect: "A"
or "B" or "C" etc.

When I put me.Controls in the watch window, I get a count of 1.

When I put Me.FindControl("hypFilt" & Request.QueryString("Filt")) in the
watch window, it comes up as Nothing.

If I hard code me.hypFiltA in the same event handler, it works fine. The
control exists and I''m able to set its properties. But I don''t want to code
all 26 letters of the alphabet into the event handler.

I tried this in other page events as well (preload, init, initcomplete,
loadcomplete, prerender, prerendercomplete... all with same results.
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:eX**************@TK2MSFTNGP06.phx.gbl...

设置断点并查看id是否正确形成,运行Me.FindControl

in观察窗口,看看Me.Controls系列内部的内容。这个
应该可以帮助你弄清楚发生了什么。


-

Eliyahu Goldin,

软件开发人员

Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http:// usefulas p.net


" Keith G Hicks" < kr*@comcast.netwrote in message

news:uF ************** @ TK2MSFTNGP05.phx.gbl ...
Set a breakpoint and see if the id is formed correctly, run Me.FindControl
in the watch window, see what is inside the Me.Controls collection. This
should help you to figure out what is going on.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Keith G Hicks" <kr*@comcast.netwrote in message
news:uF**************@TK2MSFTNGP05.phx.gbl...

我不确定我做错了什么。这是我的代码:


受保护的子Page_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)

Handles Me.Load


Dim hyp As HyperLink = CType(Me.FindControl(" hypFilt"&

Request.QueryString(" Filt" )),HyperLink)

如果不是什么不是那么

hyp.Font.Bold = True

EndIf

结束如果


我在页面上有几个超链接控件。有些是ID = hypFiltA,

hypFiltB,hypFiltC等。它们用于首先过滤一些数据
I''m not sure what I''m doing wrong. Here''s my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load

Dim hyp As HyperLink = CType(Me.FindControl("hypFilt" &
Request.QueryString("Filt")), HyperLink)
If Not hyp Is Nothing Then
hyp.Font.Bold = True
EndIf

End If

I have several hyperlink controls on a page. Some are ID = hypFiltA,
hypFiltB, hypFiltC, etc. They are used to filter some data by first



letter

letter


字母表。代码运行,没有崩溃,但上面的代码

从来没有

找到它们。 hyp always = nothing。


" hypFilt" &安培; Request.QueryString(" Filt")确实评估了正确的

值。


谢谢,


Keith
of the alphabet. The code runs, nothing crashes but but the code above
never
finds them. hyp always = nothing.

"hypFilt" & Request.QueryString("Filt") does evaluate out to the correct
value.

Thanks,

Keith




这篇关于FindControl无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆