【问题标题】:Load different ascx's in aspx page在 aspx 页面中加载不同的 ascx
【发布时间】:2015-02-25 23:18:22
【问题描述】:

在我的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 页面由于某种原因无法加载!! 我做错了什么?!?!?

【问题讨论】:

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


    【解决方案1】:

    您正试图在页面加载事件中加载用户控件。为时已晚。阅读有关Asp.Net Page Life Cycle 的更多信息。下面引用的相关部分。

    Page Event Init:在所有控件都被初始化并且 已应用任何皮肤设置。个体的Init事件 控件发生在页面的 Init 事件之前。使用此事件 读取或初始化控件属性。

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

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

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

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

    【讨论】:

    • 也许我在母版页中不清楚我有左侧和右侧....当用户单击节点时,我再次重新加载同一页面并加载页面我正在读取 QueryString 中的内容,如果它等于我的条件我正在做类似 Me.Master.FindControl("RightContent").Controls.Add(Page.LoadControl(("/Controls/Reports/rptTimeOfDay.ascx "))) 现在 ascx 已加载,但它没有出现在最后一个 ascx 的顶部,它显示在它的下方。我该怎么办?
    猜你喜欢
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 2012-08-16
    • 1970-01-01
    相关资源
    最近更新 更多