Dyamically add user control, along with properties?

S

Steve

Hello. I'm trying to dynamically load a user control which I created like this.

Dim sectionTitle1 As Control =
Page.LoadControl("~/Controls/SectionTitle.ascx")

However, I can't access any of the properties in sectionTitle1. What am I
missing?

Thank you!
 
S

Steve C. Orr [MVP, MCSD]

With the code you havenow , you can only call the properties of the standard
Control class.
You need to convert it to your class type to call your properties.

Dim MySection as MyControlClassName = CType(sectionTitle1,
MyControlClassName)
MySection.MyProperty = "whatever"
 
S

Steve

Thanks, Steve, for your reply. That was the first thing I tried, but
intellisense did not pick up the control name so I assumed it wouldn't work.
I was wrong. I am also trying this with VS.Net 2005.. maybe that's a bug?

Again, thanks for your reply.
 
M

Martin

u do use codebehind?

Steve said:
Thanks, Steve, for your reply. That was the first thing I tried, but
intellisense did not pick up the control name so I assumed it wouldn't
work.
I was wrong. I am also trying this with VS.Net 2005.. maybe that's a bug?

Again, thanks for your reply.
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top