Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic ASCX getting "Type not defined" error

Status
Not open for further replies.

patzblue

IS-IT--Management
Oct 17, 2006
5
CA
Hi, I went through the whole forum looking for a solution for my problem, but to no avail, so I'll give it a try posting and hope someone can help me figure out what my problem is.

I have a web user control called "details.ascx". Right now it's pretty empty. I use it in a ajax ModalPopup to display details about a transaction.

I have no problems dynamically loading a "normal" user control with loadControl or addressing it. But in this case, I want to load a "custom control" (if that's the word for what I'm doing).

But I keep getting the "Type not defined error". In the example I provided, all I wanted to do to test if it works is to setup a label text in my custom control

Here's the important code :

---DETAILS.ASCX----------------

<%@ Control Language="VB" ClassName="B2B_ctrls_details" AutoEventWireup="false" CodeFile="details.ascx.vb" Inherits="B2B_ctrls_details" %>

<asp:Label ID="LBId" runat="server" Text="Label" Width="289px"></asp:Label>

--DETAILS.ASCX.VB ----------------

Partial Public Class B2B_ctrls_details

Inherits System.Web.UI.UserControl

Public _ValueID As Integer

Public Property ValueID() As Integer

Get

Return _ValueID

End Get

Set(ByVal value As Integer)

_ValueID = value

End Set

End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Me.LBId.Text = Me.ValueID

End Sub



End Class

------ RECHERCHE1.ASPX , THE MAIN PAGE THAT LOADS THE CONTROL ---------

<%@ Page Language="VB" AutoEventWireup="false" EnableViewStateMac="false" ValidateRequest="false" MaintainScrollPositionOnPostback="true" Debug="true" CodeFile="recherche1.aspx.vb" Inherits="recherche1" Culture="auto:en-US" UICulture="auto" %>

<%@ Reference Control="~/B2B/ctrls/details.ascx" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register TagPrefix="uc1" TagName="WebUserControl1" Src="~/B2B/ctrls/details.ascx" %>

------- RECHERCHE1.ASPX.VB -----------------------------------

Here's the line of code that gives me that dreaded error BC30002 !

Dim SearchControl2 As B2B_ctrls_details

SearchControl2 = CType(Page.LoadControl("ctrls/details.ascx"), B2B_ctrls_details)

-----------------------------------

It chokes on that line. I've been struggling with either a "Class not accessible as no public members exist" , what I lost now somehow but whatever I try I get the type not defined error.

The thing I don't understand is that even intellisense sees my class. Doesn't give me an error at all until I try to debug or build the application then I get "1 failed"

I've looked all over the place for an answer but every trick I tried ended up with the same error.

I'm pretty desperate. Any help will be appreciated as I have a deadline coming soon.

Thanks a lot for your time.
 
try this instead
Code:
SearchControl2 = CType(Page.LoadControl("[COLOR=blue]~/[/color]ctrls/details.ascx"), B2B_ctrls_details)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hello Jason, it WORKS !!! thanks a lot !

I was under the impression it was a small thing like that. In the meantime before your reply I tested by moving my ASCX file into the root and it was working but I thought my issue was the "@reference" part of my aspx page.

Thanks a lot for your time, I was on that bug since yesterday afternoon.

Have a nice weekend and thanks again for the quick reply and fix !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top