Results 1 to 3 of 3

Thread: Loading a control within a control

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Loading a control within a control

    I'm very very tired, I might be overlooking something.

    On a page named default.aspx, I have placed a control called LeftMenu.ascx.

    Now, leftmenu.ascx itself is empty, but in its codebehind, depending upon the a certain Session variable's value, I am trying to load LeftMenuSuper.ascx or LeftMenuHeader.ascx. So, that's a control within a control.

    Here is the code in LeftMenu.ascx.vb:

    VB Code:
    1. If Session.Item(0).ToString = "normaluser" Then
    2.             Me.LoadControl("LeftMenuNormal.ascx")
    3.         Else
    4.             Me.LoadControl("LeftMenuSuper.ascx")
    5.         End If

    The problem is, nothing happens. The area where the menu is supposed to be just stays blank, and yes, both of these "child" ascx files contain HTML.

    (This is all experimental, so we won't talk about good or bad practices here.)

    Help me out, what am I doing or not doing?

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Loading a control within a control

    Correct me if I'm wrong but should it be:
    Code:
    	if (Session.Item[0].ToString() == "normaluser") {
                Control normal = LoadControl("LeftMenuNormal.ascx");
    	    Controls.Add(normal);
            } else {
                Control super = LoadControl("LeftMenuSuper.ascx");
    	    Controls.Add(super);
            }
    Sorry had to convert to C# cos my VB.NET ain't the best.

    If that doesn't work add a placeholder control onto the page and add the Dynamic User control to the placeholder's control collection.

    HTH

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Loading a control within a control

    I finally solved this in the way you've mentioned here, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width