Groups | Blog | Home
all groups > asp.net building controls > january 2004 >

asp.net building controls : Changing UserControls Dynamically


William
1/29/2004 11:30:03 PM
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]
1/30/2004 1:45:57 AM
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:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
[quoted text, click to view]

AddThis Social Bookmark Button