Changing UserControls Dynamically

W

William

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?
 
V

Victor Garcia Aprea [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top