|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Strong typing for user controlsI'm a lot confused when using user controls in ASP.NET 2.0. How do I cast a
varaible to the type of a user control... for example: Me.PlaceHolder1.Controls.Add(Page.LoadControl("~/App_Controls/ctlApplicationHome.ascx")) ' now, this doesn't work... why? Dim apl As App_Controls_ctlApplicationHome = Me.PlaceHolder1.Controls(0); Actually, let me clarify... the class "App_Controls_ctlApplicationHome" does
not exist... where is it!?! Show quoteHide quote "Ryan" wrote: > I'm a lot confused when using user controls in ASP.NET 2.0. How do I cast a > varaible to the type of a user control... for example: > > Me.PlaceHolder1.Controls.Add(Page.LoadControl("~/App_Controls/ctlApplicationHome.ascx")) > > ' now, this doesn't work... why? > Dim apl As App_Controls_ctlApplicationHome = Me.PlaceHolder1.Controls(0); > > Ryan wrote:
> I'm a lot confused when using user controls in ASP.NET 2.0. How do I cast a Dim apl As App_Controls_ctlApplicationHome => varaible to the type of a user control... for example: > > Me.PlaceHolder1.Controls.Add(Page.LoadControl("~/App_Controls/ctlApplicationHome.ascx")) > > ' now, this doesn't work... why? > Dim apl As App_Controls_ctlApplicationHome = Me.PlaceHolder1.Controls(0); CType(Me.PlaceHolder1.Controls(0), App_Controls_ctlApplicationHome) That should do it. Just curious, what .NET language are you using? It looks like VB but I notice you have a semi-colon at the very end of your last line of code. Show quoteHide quote :) Actually, here's a revised description of the issue:
I have two user controls, each of which sits in a directory called "App_Controls" in an ASP.NET 2.0 site. When I try dynamically loading Control #2 to a placeholder in Control #1, I cannot get a strongly typed reference to that control, because the Type "App_Controls_ctlApplicationHome" is not defined. Does that make sense? (to answer your question, I'm a C# developer working on a VB.NET project, hence the schizophrenic coding) Show quoteHide quote "tdavisjr" wrote: > > Ryan wrote: > > I'm a lot confused when using user controls in ASP.NET 2.0. How do I cast a > > varaible to the type of a user control... for example: > > > > Me.PlaceHolder1.Controls.Add(Page.LoadControl("~/App_Controls/ctlApplicationHome.ascx")) > > > > ' now, this doesn't work... why? > > Dim apl As App_Controls_ctlApplicationHome = Me.PlaceHolder1.Controls(0); > > Dim apl As App_Controls_ctlApplicationHome = > CType(Me.PlaceHolder1.Controls(0), App_Controls_ctlApplicationHome) > > That should do it. > > Just curious, what .NET language are you using? It looks like VB but I > notice you have a semi-colon at the very end of your last line of code. > :) > > On Fri, 13 Jan 2006 09:34:02 -0800, "Ryan"
<R***@discussions.microsoft.com> wrote: > You need an @ Reference in your aspx page to the user control. >I have two user controls, each of which sits in a directory called >"App_Controls" in an ASP.NET 2.0 site. When I try dynamically loading Control >#2 to a placeholder in Control #1, I cannot get a strongly typed reference to >that control, because the Type "App_Controls_ctlApplicationHome" is not >defined. > <%@ Reference VirtualPath="~/Products.ascx" %> That will make sure the user control type is visible in your code file. Example: http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx Ah, of course! Thanks!
Show quoteHide quote "Scott Allen" wrote: > On Fri, 13 Jan 2006 09:34:02 -0800, "Ryan" > <R***@discussions.microsoft.com> wrote: > > > > >I have two user controls, each of which sits in a directory called > >"App_Controls" in an ASP.NET 2.0 site. When I try dynamically loading Control > >#2 to a placeholder in Control #1, I cannot get a strongly typed reference to > >that control, because the Type "App_Controls_ctlApplicationHome" is not > >defined. > > > > You need an @ Reference in your aspx page to the user control. > > <%@ Reference VirtualPath="~/Products.ascx" %> > > That will make sure the user control type is visible in your code > file. > > Example: > http://odetocode.com/Blogs/scott/archive/2005/06/30/1889.aspx > > -- > Scott > http://www.OdeToCode.com/blogs/scott/ >
Other interesting topics
Only allow enter key in MultiLine textbox
Deriving from MembershipUser and ASPNET Config Tool ASP.net and thread safety MSWord DataGrid, Edit and the Enter Key Dot Net or Javascript problem??? ASP.NET Embedded Resources delegation question Very Strange Problem! (Derived Controls) - Help! sending email |
|||||||||||||||||||||||