PC Review


Reply
Thread Tools Rate Thread

code-behind error in user control

 
 
xgngli@gmail.com
Guest
Posts: n/a
 
      22nd Aug 2006
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

 
Reply With Quote
 
 
 
 
xgngli@gmail.com
Guest
Posts: n/a
 
      22nd Aug 2006
OK. The bin directory needs to be placed directly under the wwwroot
directory; or directly under the virtual directory. That's it!

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control Code-Behind rn5a@rediffmail.com Microsoft ASP .NET 2 22nd Nov 2006 04:59 PM
Control Inheritance in Code (without using Web User Control) rodwilnot Microsoft ASP .NET 2 9th Nov 2006 02:21 PM
Error with code-behind for user control Alan Silver Microsoft ASP .NET 3 20th Mar 2006 02:04 PM
NO Code behind with user control - PLEASE! Amar Microsoft ASP .NET 2 24th Jun 2005 09:26 AM
RE: How to access page code behind from User Control code behind Tian Min Huang Microsoft Dot NET 4 23rd Mar 2004 01:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.