【发布时间】:2011-10-28 20:49:38
【问题描述】:
我创建了一个包含许多自定义 .ascx 控件的 .aspx 页面,我想创建一个页面函数,为每个控件生成一个工具提示。我创建了一个接口,每个 .ascx 控件都实现了该接口来创建工具提示(该函数称为 GetToolTipInfo(),所以我现在需要的是一种通过它的 ID 动态引用 .ascx 控件的方法。
这是我目前正在尝试使用的功能...
Protected Sub SetToolTip(sender As Object, args As ToolTipUpdateEventArgs)
Dim control As New Literal()
Dim info As ToolTipInfo = CType(Me.FindControl(args.TargetControlID).Parent, FormFunction).GetToolTipInfo()
control.Text = info.content
RadToolTipManagerMain.Width = info.width
RadToolTipManagerMain.Position = info.position
args.UpdatePanel.ContentTemplateContainer.Controls.Clear()
args.UpdatePanel.ContentTemplateContainer.Controls.Add(control)
End Sub
事实上,FindControl 什么也不返回。我可以将每个控件引用硬编码到这个函数中,但想知道是否有更优雅的方法。如果有任何关系,我也会使用母版页和内容面板。
感谢您的任何建议。
【问题讨论】:
-
也许这会有所帮助:sharpertutorials.com/recursive-findcontrol 因为控件可能位于某种容器中。而且我只是认为发件人不是您正在寻找的控件,而是一些不同的控件?
标签: asp.net ascx findcontrol