开发者

added 3 tree views in my master page,but they r not visible

I added 3 tree views in my master page, i want them to show them based on different conditions, but they are not visible on other pages.

Code:

    Dim TreeView1 As System.Web.UI.WebControls.TreeView = New TreeView
    Dim TreeView2 As System.Web.UI.WebControls.TreeView = New TreeView
    Dim TreeView3 As System.Web.UI.We开发者_运维技巧bControls.TreeView = New TreeView
    Dim str As String = HttpContext.Current.Profile.GetPropertyValue("UserType")
    Select Case (str)
        Case "Faculty"
            Response.Write("Faculty")
            TreeView1.Visible = True
            Exit Select
        Case "Admin"
            Response.Write("Admin")
            TreeView2.Visible = True
            Exit Select
        Case "Student"
            Response.Write("Student")
            TreeView3.Visible = True
            Exit Select
    End Select

Please let me know how to resolve this problem.


Call Controls.Add(TreeView1).

If this doesn't help, please provide more detail.


Do this.

Dim TreeView1 As System.Web.UI.WebControls.TreeView = New TreeView
Dim TreeView2 As System.Web.UI.WebControls.TreeView = New TreeView
Dim TreeView3 As System.Web.UI.WebControls.TreeView = New TreeView
Dim str As String = HttpContext.Current.Profile.GetPropertyValue("UserType")
Select Case (str)
    Case "Faculty"
        Response.Write("Faculty")
        TreeView1.Visible = True
        Page.Controls.Add(Treeview1)
        Exit Select
    Case "Admin"
        Response.Write("Admin")
        TreeView2.Visible = True
        Page.Controls.Add(Treeview2)
        Exit Select
    Case "Student"
        Response.Write("Student")
        TreeView3.Visible = True
        Page.Controls.Add(Treeview3)
        Exit Select
End Select


This question is fairly old, but an answer was never marked on it. I believe that it is a common enough problem to place an answer out on Stack Overflow.

Rather than calling

Page.Controls.Add(Treeview1)

try calling

Page.Form.Controls.Add(Treeview1)

adding it to the Form and not directly to the Page.

David

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜