Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP 2.0, how do I dynamically add a user control?

Status
Not open for further replies.

NBartomeli

Programmer
Jul 1, 2003
111
US
In 1.1, I was able to say something like

Code:
dim x as control = loadcontrol("../control.ascx")
Controls.add(x)

dim y as MyCustomControlType = CType(x, MyCustomControlType)
'or
CType(x, MyCustomControlType).SomeParameter = 1234

Since everything is partial classes in 2.0, how can I accomplish this?

Thanks.
 
Since everything is partial classes in 2.0,
What difference does that make to what you are trying to do? Also, what is actually your problem? Is it that you can't load a control (like your "x" example) or is it that you can't cast a control (like your "y" example)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Or is it that you've actuall created a UserControl and you just want to dynamically add it to the page?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I want to be able to dynamically add it to a page, then cast an object as that type of control so I can call a method of that control.

I want to be able to do this:
Code:
Dim X as control = LoadControl("../controlX.ascx")
Controls.add(x)

Dim i as integer = CType(X, ControlX).DoSomething(1,2)

hope this clears things up a little.

Thanks in advance
 
And if you do mean what I said in my second post, simly use:
Code:
        Dim x As New Control
        x = LoadControl("MyUserControl.ascx")
        Panel1.Controls.Add(x)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The code-behind still doesn't know the TYPE of X though, so when you type

"X." you get a generic list of object methods/etc.. not the one's that are marked as public for the type of control.

So thats a start, but I need to be able to call functions on the user control, so it needs to know the type.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top