最初有单独的aspx页面,所有页面都运行良好,然后我不得不将其实现到母版页中。这段代码是几年前完成的,现在需要转换为html5。
当我明确提到控制名称时,工作原理是什么
'find contentplaceholder
Dim mpContentPlaceHolder As ContentPlaceHolder
mpContentPlaceHolder = CType(Master.FindControl("HomePlaceholder"), ContentPlaceHolder)
'find the control
AnnounceSnippet = DirectCast(mpContentPlaceHolder.FindControl("AnnounceSnippet"), Control.ContentSnippet)
在实施主模板之前,以下内容工作良好
#Region "View Particular Day"
Public Sub lbtDayView_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dtmSelectedDate As DateTime = DirectCast(Page.FindControl(DirectCast(sender, Calendar).ClientID), Calendar).SelectedDate()
但后来,由于它给出了空指针异常,我尝试使用主内容持有者
Dim dtmSelectedDate As DateTime = DirectCast(mpContentPlaceHolder.FindControl(DirectCast(sender, Calendar).ClientID), Calendar).SelectedDate()
仍然没有线索。
有人能帮忙吗>
这是我的aspx
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="HomePlaceholder">
......
<uc1:contentsnippet id="AnnounceSnippet" runat="server"></uc1:contentsnippet>
.....
<asp:calendar id="Calendar1" runat="server"></asp:calendar>
</asp:Content>
啊找到了!!!。
当我对它进行调试时,它返回了"HomePlaceholder_Calendar1"作为客户端ID,而不仅仅是"Calendar1",字符串替换也是如此,我知道这不是正确的方法,但这是我现在唯一的方法。