在aspx页面中加载不同的ascx

时间:2015-02-25 23:18:23

标签: c# asp.net vb.net treeview

在我的aspx页面上,我在TreeView的每个节点的左侧都有TreeView,我想加载一个不同的ascx,它只会改变页面的右侧。

这就是我的aspx.vb的样子:

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

    RetrieveAllQueryStringParams()

    If Not IsPostBack Then
        GenerateDataSets()
        GenerateLabels()
        GenerateLinks()
        GenerateControls()
        GenerateOther()
    End If

End Sub

当它到达GenerateLinks()

 Protected Sub GenerateLinks()
        Dim subTreeStatisticalReport As RadTreeNode = rtvReports.Nodes.FindNodeByValue("StatisticalReport")
        Dim subTreeIncidentComparisons As RadTreeNode = rtvReports.Nodes.FindNodeByValue("IncidentComparisons")
        Dim subTreeGeographicLocations As RadTreeNode = rtvReports.Nodes.FindNodeByValue("GeographicLocations")

        Dim statTimeOfDayNode As RadTreeNode = subTreeStatisticalReport.Nodes.FindNodeByValue("TimeofDay")
        Dim statTrendsNode As RadTreeNode = subTreeStatisticalReport.Nodes.FindNodeByValue("Trends")
        Dim statTopSevenIncidents As RadTreeNode = subTreeStatisticalReport.Nodes.FindNodeByValue("Top7Incidents")
        Dim statIncidentPerCategory As RadTreeNode = subTreeStatisticalReport.Nodes.FindNodeByValue("IncidentsPerCategory")
        Dim compIncidentLoss As RadTreeNode = subTreeIncidentComparisons.Nodes.FindNodeByValue("IncidentLoss")
        Dim GeoMaps As RadTreeNode = subTreeGeographicLocations.Nodes.FindNodeByValue("Maps")




        statTimeOfDayNode.NavigateUrl = Globals.gRootRelativeSecureURL("/Reports/Reports.aspx?SessionID=" + m_SessionID + "&qrptTOD=tod")
End Sub

现在,如果用户要点击时间节点,它将再次加载相同的页面但不同的ascx。

Private Sub RetrieveAllQueryStringParams()
        Try
            If Not String.IsNullOrEmpty(Request.QueryString("SessionID")) Then
                m_SessionID = Request.QueryString("SessionID")
                m_qrptTOD = Request.QueryString("qrptTOD")
            ElseIf Not String.IsNullOrEmpty(Session("SessionID")) Then
                m_SessionID = Session("SessionID")
            End If

            If m_qrptTOD = "tod" Then
                Page.LoadControl("/Controls/Reports/rptTimeOfDay.ascx")
            End If


        Catch ex As Exception

        End Try
    End Sub

当它到达时:

 If m_qrptTOD = "tod" Then
                Page.LoadControl("/Controls/Reports/rptTimeOfDay.ascx")
            End If

由于某种原因,ascx页面没有加载!! 我做错了什么?!?!?

1 个答案:

答案 0 :(得分:0)

您正尝试在Page Load事件中加载用户控件。太晚了。详细了解Asp.Net Page Life Cycle。相关部分引用如下。

  

页面事件初始化:在初始化所有控件之后引发   已应用任何皮肤设置。个人的Init事件   控件发生在页面的Init事件之前。使用此事件   读取或初始化控件属性。

您需要在此活动之前加载您的控件。

您可以控制ascx文件的可见性,而不是Page.LoadControl(“UserControlPath”)。请尝试以下代码。

If m_qrptTOD = "tod" Then
       ascxRptTimeOfDay.Visible = False
End If

请注意,您的rptTimeOfDay.ascx UserControl将始终以此方法加载,您只需更改其可见性。但是,在Asp.NET中,如果用户控件不可见,则不会向客户端发送HTML代码。

相关问题