I guess I should be directing these questions to Stephen Walther directly
but I am not sure how to contact him.
In ASP.NET Unleashed (pp. 274-275) There is a sample
<Script runat="Server">
Sub Page_Load
Dim strFeatured As String
Dim RanNum As New Random
Dim ctlControl As Control
strFeatured = "Featured" & RanNum.Next( 1, 3 ) & ".ascx"
ctlControl = LoadControl( strFeatured )
Ctype( ctlControl, FeaturedProduct ).BackColor="Orange"
plhFeatured.Controls.Add( ctlControl )
End Sub
</Script>
<html>
<head><title>DisplayFeaturedProductCodeBehind.aspx</title></head>
<body>
<asp:PlaceHolder
id="plhFeatured"
Runat="Server" />
</body>
</html>
When I try to run it I get the following error. Any idea what is wrong? I
have recompiled the FeaturedProduct.vb code behind and made sure that it is
in the bin directory but I still get the error.
Kevin
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'FeaturedProduct' is not defined.
Source Error:
Line 8: strFeatured = "Featured" & RanNum.Next( 1, 3 ) & ".ascx"
Line 9: ctlControl = LoadControl( strFeatured )
Line 10: Ctype( ctlControl, FeaturedProduct ).BackColor="Orange"
Line 11: plhFeatured.Controls.Add( ctlControl )
Line 12: End Sub
Source File:
H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehind.aspx Line:
10
Show Detailed Compiler Output:
C:\WINNT\system32> "c:\winnt\microsoft.net\framework\v1.0.3705\vbc.exe"
/t:library /utf8output
/R:"c:\winnt\assembly\gac\system.drawing\1.0.3300.0__b03f5f7f11d50a3a\system
.drawing.dll"
/R:"c:\winnt\assembly\gac\system.data\1.0.3300.0__b77a5c561934e089\system.da
ta.dll"
/R:"c:\winnt\assembly\gac\system\1.0.3300.0__b77a5c561934e089\system.dll"
/R:"c:\winnt\assembly\gac\system.web\1.0.3300.0__b03f5f7f11d50a3a\system.web
.dll"
/R:"c:\winnt\assembly\gac\system.web.services\1.0.3300.0__b03f5f7f11d50a3a\s
ystem.web.services.dll"
/R:"c:\winnt\assembly\gac\system.enterpriseservices\1.0.3300.0__b03f5f7f11d5
0a3a\system.enterpriseservices.dll"
/R:"c:\winnt\assembly\gac\system.xml\1.0.3300.0__b77a5c561934e089\system.xml
.dll" /out:"C:\WINNT\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET
Files\aspx\418ba5e4\e69c9302\alhpfsuo.dll" /debug-
"C:\WINNT\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET
Files\aspx\418ba5e4\e69c9302\alhpfsuo.0.vb"
Microsoft (R) Visual Basic .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.00.3705.209
Copyright (C) Microsoft Corporation 1987-2001. All rights reserved.
H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehind.aspx(10) :
error BC30002: Type 'FeaturedProduct' is not defined.
Ctype( ctlControl, FeaturedProduct ).BackColor="Orange"
~~~~~~~~~~~~~~~
Show Complete Compilation Source:
Line 1:
'---------------------------------------------------------------------------
---
Line 2: ' <autogenerated>
Line 3: ' This code was generated by a tool.
Line 4: ' Runtime Version: 1.0.3705.209
Line 5: '
Line 6: ' Changes to this file may cause incorrect behavior and will
be lost if
Line 7: ' the code is regenerated.
Line 8: ' </autogenerated>
Line 9:
'---------------------------------------------------------------------------
---
Line 10:
Line 11: Option Strict Off
Line 12: Option Explicit On
Line 13:
Line 14: Imports Microsoft.VisualBasic
Line 15: Imports System
Line 16: Imports System.Collections
Line 17: Imports System.Collections.Specialized
Line 18: Imports System.Configuration
Line 19: Imports System.Text
Line 20: Imports System.Text.RegularExpressions
Line 21: Imports System.Web
Line 22: Imports System.Web.Caching
Line 23: Imports System.Web.Security
Line 24: Imports System.Web.SessionState
Line 25: Imports System.Web.UI
Line 26: Imports System.Web.UI.HtmlControls
Line 27: Imports System.Web.UI.WebControls
Line 28:
Line 29: Namespace ASP
Line 30:
Line 31: Public Class DisplayFeaturedProductCodeBehind_aspx
Line 32: Inherits System.Web.UI.Page
Line 33: Implements System.Web.SessionState.IRequiresSessionState
Line 34:
Line 35: Private Shared __autoHandlers As Integer
Line 36:
Line 37:
Line 38:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",20)
Line 39: Protected plhFeatured As
System.Web.UI.WebControls.PlaceHolder
Line 40:
Line 41: #End ExternalSource
Line 42:
Line 43: Private Shared __intialized As Boolean = false
Line 44:
Line 45: Private Shared __fileDependencies As
System.Collections.ArrayList
Line 46:
Line 47:
Line 48:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",1)
Line 49:
Line 50:
Line 51: Sub Page_Load
Line 52: Dim strFeatured As String
Line 53: Dim RanNum As New Random
Line 54: Dim ctlControl As Control
Line 55:
Line 56: strFeatured = "Featured" & RanNum.Next( 1, 3 ) & ".ascx"
Line 57: ctlControl = LoadControl( strFeatured )
Line 58: Ctype( ctlControl, FeaturedProduct ).BackColor="Orange"
Line 59: plhFeatured.Controls.Add( ctlControl )
Line 60: End Sub
Line 61:
Line 62:
Line 63: #End ExternalSource
Line 64:
Line 65: Public Sub New()
Line 66: MyBase.New
Line 67: Dim dependencies As System.Collections.ArrayList
Line 68: If
(ASP.DisplayFeaturedProductCodeBehind_aspx.__intialized = false) Then
Line 69: dependencies = New System.Collections.ArrayList
Line 70:
dependencies.Add("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBeh
ind.aspx")
Line 71:
ASP.DisplayFeaturedProductCodeBehind_aspx.__fileDependencies = dependencies
Line 72:
ASP.DisplayFeaturedProductCodeBehind_aspx.__intialized = true
Line 73: End If
Line 74: End Sub
Line 75:
Line 76: Protected Overrides Property AutoHandlers As Integer
Line 77: Get
Line 78: Return
ASP.DisplayFeaturedProductCodeBehind_aspx.__autoHandlers
Line 79: End Get
Line 80: Set
Line 81:
ASP.DisplayFeaturedProductCodeBehind_aspx.__autoHandlers = value
Line 82: End Set
Line 83: End Property
Line 84:
Line 85: Protected ReadOnly Property ApplicationInstance As
System.Web.HttpApplication
Line 86: Get
Line 87: Return
CType(Me.Context.ApplicationInstance,System.Web.HttpApplication)
Line 88: End Get
Line 89: End Property
Line 90:
Line 91: Public Overrides ReadOnly Property
TemplateSourceDirectory As String
Line 92: Get
Line 93: Return "/ASPX/Chapter05"
Line 94: End Get
Line 95: End Property
Line 96:
Line 97: Private Function __BuildControlplhFeatured() As
System.Web.UI.Control
Line 98: Dim __ctrl As System.Web.UI.WebControls.PlaceHolder
Line 99:
Line 100:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",20)
Line 101: __ctrl = New System.Web.UI.WebControls.PlaceHolder
Line 102:
Line 103: #End ExternalSource
Line 104: Me.plhFeatured = __ctrl
Line 105:
Line 106:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",20)
Line 107: __ctrl.ID = "plhFeatured"
Line 108:
Line 109: #End ExternalSource
Line 110: Return __ctrl
Line 111: End Function
Line 112:
Line 113: Private Sub __BuildControlTree(ByVal __ctrl As
System.Web.UI.Control)
Line 114: Dim __parser As System.Web.UI.IParserAccessor =
CType(__ctrl,System.Web.UI.IParserAccessor)
Line 115:
Line 116:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",1)
Line 117: __parser.AddParsedSubObject(New
System.Web.UI.LiteralControl("
"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&Microsoft.Vi
sualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&"<html>"&Microsoft.VisualB
asic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&"<head><title>DisplayFeaturedPr
oductCodeBehind.aspx</title></head>"&Microsoft.VisualBasic.ChrW(13)&Microsof
t.VisualBasic.ChrW(10)& _
Line 118:
"<body>"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&Micro
soft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)))
Line 119:
Line 120: #End ExternalSource
Line 121:
Line 122:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",1)
Line 123: Me.__BuildControlplhFeatured
Line 124:
Line 125: #End ExternalSource
Line 126:
Line 127:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",1)
Line 128: __parser.AddParsedSubObject(Me.plhFeatured)
Line 129:
Line 130: #End ExternalSource
Line 131:
Line 132:
#ExternalSource("H:\AspNetUnleashed\Chapter05\DisplayFeaturedProductCodeBehi
nd.aspx",1)
Line 133: __parser.AddParsedSubObject(New
System.Web.UI.LiteralControl(""&Microsoft.VisualBasic.ChrW(13)&Microsoft.Vis
ualBasic.ChrW(10)&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(
10)&"</body>"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&
"</html>"))
Line 134:
Line 135: #End ExternalSource
Line 136: End Sub
Line 137:
Line 138: Protected Overrides Sub FrameworkInitialize()
Line 139: Me.__BuildControlTree(Me)
Line 140: Me.FileDependencies =
ASP.DisplayFeaturedProductCodeBehind_aspx.__fileDependencies
Line 141: Me.EnableViewStateMac = true
Line 142: End Sub
Line 143:
Line 144: Public Overrides Function GetTypeHashCode() As Integer
Line 145: Return -781801125
Line 146: End Function
Line 147: End Class
Line 148: End Namespace
Line 149:
_____
Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
Version:1.0.3705.0
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.