X
xgngli
In ASP.NET Unleashed (pp. 274-275) There is a sample
DisplayFeaturedProductCodeBehind.aspx:
<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>
<asplaceHolder
id="plhFeatured"
Runat="Server" />
</body>
</html>
Featured1.ascx has the following content: (Featured2.ascx is similar)
<%@ Inherits="FeaturedProduct" %>
<table width="200" cellpadding="10"
cellspacing="0" bgcolor="<%=BackColor%>">
<tr>
<td>
<h3>Hammers on Sale!</h2>
Quality hammers are now on sale in the
hardware department.
</td>
</tr>
</table>
FeaturedProduct.vb has the following:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class FeaturedProduct
Inherits UserControl
Public BackColor As String = "lightgreen"
End Class
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.
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:
c:\inetpub\wwwroot\unleashed\chapter05\vb\DisplayFeaturedProductCodeBehind.aspx
Line: 10
DisplayFeaturedProductCodeBehind.aspx:
<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>
<asplaceHolder
id="plhFeatured"
Runat="Server" />
</body>
</html>
Featured1.ascx has the following content: (Featured2.ascx is similar)
<%@ Inherits="FeaturedProduct" %>
<table width="200" cellpadding="10"
cellspacing="0" bgcolor="<%=BackColor%>">
<tr>
<td>
<h3>Hammers on Sale!</h2>
Quality hammers are now on sale in the
hardware department.
</td>
</tr>
</table>
FeaturedProduct.vb has the following:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class FeaturedProduct
Inherits UserControl
Public BackColor As String = "lightgreen"
End Class
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.
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:
c:\inetpub\wwwroot\unleashed\chapter05\vb\DisplayFeaturedProductCodeBehind.aspx
Line: 10