How to declare & access pre-complied usercontrols from page codebehind?

N

N. Demos

I have a user control with code behind of which two instances are
created/declared in my aspx page. The aspx page has code behind also, as
I need to access methods of the usercontrols on page submit.

I've read several post here and articles on the web on this topic. What
little I have learned from them is that you have to pre-compile the
usercontrol in order to access it in the aspx code behind. I did this,
compiling the usercontrol (CityGeoPosListBoxClass) into an assembly
(CityGeoPosSelectVB.dll), but I still can't get the app to compile. The
error I'm getting presently is:

Compiler Error Message: BC30002: Type 'CityGeoPosListBoxClass' is not
defined.

Source Error:
Line 12: Public Const dRadiusEarth As Double = 6366.707
Line 13:
Line 14: Public ucCityListBox1 As CityGeoPosListBoxClass
Line 15: Public ucCityListBox2 As CityGeoPosListBoxClass
Line 16:

, which is in Test.vb.

I believe my problems are how I set up the <@Control > and <@Register >
tags in the ascx and asp file, and not understanding how to
declare/reference the usercontrols in the aspx codebehind. So my
questions are:

What needs to go in the <@Control > and <@Register > tags to properly
register and access the assembly and it's usercontrols?

How exactly do you reference the controls in the aspx page code behind?

I'd appreciate any help on what I'm doing wrong here.

Thanks and Regards,
N. Demos


File List:
-----------
CityGeoPosSelect.ascx (usercontrol)
CityGeoPosSelect.vb (code behind for usercontrol)
Test.aspx (main page)
Test.vb (code behind for main page)


Here's the relevent code:
---------------------------

'********** CityGeoPosSelect.ascx **********
<%@ Control language="vb" inherits="CityGeoPosListBoxClass"
assembly="CityGeoPosSelectVB" %>

'a listbox and a couple textboxes ...



'********** CityGeoPosSelect.vb **********
Option Explicit
Option Strict

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.IO
Imports System.XML

Namespace GeoPos

Public Class CityGeoPosListBoxClass : Inherits System.Web.UI.UserControl
' Stuff ...
End Class
End Namespace



'********** Test.vb **********
Option Explicit
Option Strict

Imports System
Imports System.Collections
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports GeoPos


Public Class TestCodebehind : Inherits Page
Public Const dRadiusEarth As Double = 6366.707

Public ucCityListBox1 As CityGeoPosListBoxClass
Public ucCityListBox2 As CityGeoPosListBoxClass

' Other stuff ...
End Class



'********** Test.aspx **********
<%@ PAGE language="VB" debug="true" SmartNavigation="true" src="Test.vb"
inherits="TestCodebehind" %>
<%@ Register tagprefix="geo" namespace="GeoPos"
assembly="CityGeoPosSelectVB" %>

<html>
<body>
<form method="post" runat="server">
<geo:CityGeoPosListBoxClass id="ucCityListBox1" runat="server" />
<br />

<geo:CityGeoPosListBoxClass id="ucCityListBox2" runat="server" />
<br />
</div>
</form>
 
G

Guest

To put it simply, just create the user controls in your own projects itself,
and raise event from the user control. Capture these events in the page which
you are using.
 
N

N. Demos

Prakash.NET said:
To put it simply, just create the user controls in your own projects itself,
and raise event from the user control. Capture these events in the page which
you are using.
Prakash,
Thanks for replying. I'm not sure what you mean by raise events from the
control. I'm somewhat of a beginner with ASP.NET. Also, I'm not using
Visual Studio.

Basically, my usercontrol is an asp:listbox and an asp:textbox, with the
SelectedIndexChanged event handled on the listbox (which displays the
value of the selected listbox item in the textbox. The page has two of
these usercontrols, another textbox and a submit button. The onclick
event of the submit button gets the values from each of the selected
items in the usercontrol's listboxes, performs a calculation with them
and displays the result in the pages textbox.

Regards,
N. Demos
 

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

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top