code-behind error in user control

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>

<asp:placeHolder
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
 
X

xgngli

OK. The bin directory needs to be placed directly under the wwwroot
directory; or directly under the virtual directory. That's it!
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top