我有一个包含 LinkButton 的用户控件,单击该控件时会调用父类中的子类。当我单击 LinkButton 时,该子被调用 OK,但该子中引用的对象都触发了空对象引用错误。我究竟做错了什么?
为了使事情尽可能简短,我只在他们的类中显示相关的子项。
这是用户控件的LinkClick子:
Public Class Dashboard
Inherits System.Web.UI.UserControl
...(Other code here)...
Private Sub LinkClick(sender As Object, e As CommandEventArgs)
Dim action = e.CommandArgument
Dim cls As New MainPage
cls.Dashboard_Clicked(action)
End Sub
End Class
这是通过 LinkClick 调用子类的父类:
Imports System.IO
Public Class MainPage
Inherits System.Web.UI.UserControl
...(Other code here)...
Public Sub Dashboard_Clicked(action)
mpe.Show()
End Sub
End Class
这是父控件上的标记,它显示了用户控件的标记和我在子控件中尝试引用失败的对象的标记:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TSEnterHours.ascx.vb"
Inherits="App.MainPage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="Dashboard.ascx" TagName="Dashboard" TagPrefix="uc" %>
<uc:Dashboard SourceProcName="Dashboard.QueryName" runat="server">
<DashboardParameters>
<dashboardparameter name="aID" useenvironmentvalue="aID" />
</DashboardParameters>
<Items>
<item type="hyperlink" Action="PTO_Clicked" label="YTD PTO Taken" field="TotalPTO" />
</Items>
</uc:Dashboard>
<!-- Other code... -->
<asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnDummy" PopupControlID="PTOPanel"
BackgroundCssClass="ModalPopupBG" OkControlID="btnDummy" CancelControlID="btnDummy"
BehaviorID="mpeBehavior_PTO" />
顺便说一句,“父”类本身就是一个在选项卡容器内操作的用户控件。我不认为这有什么不同,但我认为我应该提一下以防万一。