Changing UserControls Dynamically

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Changing UserControls Dynamically

    I have 2 user controls and I would like to display 1 of them depending on a
    session variable. I have trie a place holder, but it doesnt seem to work.

    ie..
    Select Case Session("Variable")
    Case "1"
    PlaceHolder1.Controls.Add(New MyControl1)
    Case "2"
    PlaceHolder1.Controls.Add(New MyControl2)
    End Select

    this code does not seem to do anything. How can I acheive this behavior?


    William Guest

  2. Similar Questions and Discussions

    1. Dynamically changing chart labels
      HI I'm after an how too really, point me in the right direction is possible. I have a new dashboard app, monitoring a server, last part is load...
    2. Dynamically loading and adding usercontrols after CreateChildControls
      Hi, I'm having a problem with loading and adding usercontrols dynamically after CreateChildControls. To be more specific, I have a number of...
    3. Changing Text Dynamically
      Hello, I would like to know if the text displayed on a webpage changes dynamically.I have 2 drop down menus and based on the options chosen I...
    4. Events not firing on dynamically added UserControls
      I am trying to dynamically add a user control to a Custom Control that inherits a Panel. The control renders fine on the web form. The problem is...
    5. Changing module dynamically
      Thomas M. Widmann sikyal: I'm not sure how much control you have over the architecture of the whole thing, but this is how I would implement...
  3. #2

    Default Re: Changing UserControls Dynamically

    Hi William,

    You need to call the LoadControl method to get an instance of an UserControl
    and not the new operator.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    [url]http://obies.com/vga/blog.aspx[/url]

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    "William" <wreyes@optonline.net> wrote in message
    news:OLBd4lu5DHA.2404@TK2MSFTNGP12.phx.gbl...
    > I have 2 user controls and I would like to display 1 of them depending on
    a
    > session variable. I have trie a place holder, but it doesnt seem to work.
    >
    > ie..
    > Select Case Session("Variable")
    > Case "1"
    > PlaceHolder1.Controls.Add(New MyControl1)
    > Case "2"
    > PlaceHolder1.Controls.Add(New MyControl2)
    > End Select
    >
    > this code does not seem to do anything. How can I acheive this behavior?
    >
    >

    Victor Garcia Aprea [MVP] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139