User Controls and Form Inheritance - How to Declare Them?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Charles M. Carroll (VIP)
Here is the problem again --- asked on [aspngreuse] and [aspngfreeforall]
without a resolution.

I have a 2,000 line .aspx script I am splitting into two pieces along the
lines of:
http://www.learnasp.com/freebook/learn/visualinheritance.aspx

I have fixed 90% of the compile errors after converting it by adding many
protected statements, i.e.

protected EmailPrevious as dropdownlist
protected passw as htmlInputText
protected UserID as htmlInputText
protected ModAspNG as checkbox
protected ModAsp as checkbox
etc.

But what do I do about a User Control on the original page, i.e.
<%@ Register TagPrefix="CBBMail" TagName="SendListMail"
Src="/CharlesTeam/BrianBilbro/common/UserControls/SendListMail.ascx" %>

which is used on the page ala:
<CBBMail:SendListMail id="ListMailForm" runat="server"/>

How do I declare it? i.e.
protected listmailform as ???????

If I leave it at the page level I eventually get the following error:
The name 'ListMailForm' is not declared.

Declaring it as object (a move of desparation) does not work.

At the code that registers its events it throws an error of course:

AddHandler ListMailForm.SentMessage , AddressOf evntMailForm_SentMessage
AddHandler ListMailForm.CancelMessage , AddressOf evntMailForm_CancelMessage

Ala:
http://docs.learnasp.com/quickstart/aspplus/doc/webpagelets.aspx#program

I tried

Attempt A:
Adding <%@ Control ClassName="SendListMail" %> to the .ascx file
Dim LMF as Control =
loadControl("/CharlesTeam/BrianBilbro/common/UserControls/SendListMail.ascx")
and using Ctype(LMF,SendListMail) everywhere the control was
referenced. That was not the answer. Type is not defined: 'SendListMail'

Attempt B:
An attempt to add LMF to page ala:
Controls.Add (LMF)
results in error: "Expected either a variable, constant, Enum, Type, or
procedural declaration"

I have received other suggestions that I was not clear how to implement and
left me scratching my head.

Suggestion #1
In order to access the code, I believe you will have to compile the user
control code, or at least move it to its own vb or cs file like you showed
at http://www.learnasp.com/freebook/syntax/objectvb1.aspx, (although I have
never personally left it in a vb or cs file, I would guess it should work).
Once compiled (and the namespace has been imported) you will be able to
reference is via traditional methods:
protected listmailform as SendListMail

Suggestion #2
Ok, here's what I've tried and what works. The way I have referenced UCs
was by either:
1. In an .aspx or .ascx page and just used the @ reference and refered to
the control as ASP.ControlPage_ascx
2. Or I referenced in a visual studio asp.net project and in the code
behind page. In that case you just import the project namespace in your
codebehind and then you can reference the control like so:
Imports MyProjectNamespace
......code....
Protected WithEvents MyControlInstances As MyProjectNamespace.MyControl
I have attached a simple VS.NET project that demos this.
but..but..but...what I haven't done is reference a user control is a
code-behind that is *not* precompiled (VS.net precompiles the codebehind).
This appears to be your situation. And it might not be possible to
reference it in the code-behind (at least with beta2). I haven't worked a
whole lot on this though. I tried a few things but couldn't get it to work.
What I might be able to do is precompile the SendMailForm User Control and
put the DLL in the bin directory. Then you should be able to reference it
then. I'll let you know when I get that (and probably a test page with it).
Reply to this message...
 
    
G. Andrew Duthie (VIP)
If you're trying to reference a User Control across application
boundaries, that will likely cause you problems. If something needs to
be reused in multiple applications, it should be designed as an ASP.NET
server control, compiled, given a strong name, and installed in the
Global Assembly Cache (GAC). Then, all applications residing on that
server will have access to the control by adding an @ Register directive
to the page (or control) containing the desired tag prefix to use, the
namespace defined for the control, and the assembly name of the control
(including the version # for controls installed in the GAC).

I would definitely consider refactoring the User Control into a custom
server control, and see if that doesn't make the process work for you.

Regards,

--
G. Andrew Duthie
Graymad Enterprises, Inc.
Click here to reveal e-mail address
Author, ASP.NET Step By Step
http://www.amazon.com/exec/obidos/ASIN/0735612870/

[Original message clipped]

Reply to this message...
 
    
Jeff Widmer
Is the SendListMail.ascx inheriting from a code-behind file also? Or does
it only include script blocks?

Can you post some of the SendListMail.ascx file?

-----Original Message-----
From: Charles M. Carroll [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 5:01 PM
To: aspngescalate
Subject: [aspngescalate] User Controls and Form Inheritance - How to
Declare Them?

Here is the problem again --- asked on [aspngreuse] and [aspngfreeforall]
without a resolution.

I have a 2,000 line .aspx script I am splitting into two pieces along the
lines of:
http://www.learnasp.com/freebook/learn/visualinheritance.aspx

I have fixed 90% of the compile errors after converting it by adding many
protected statements, i.e.

protected EmailPrevious as dropdownlist
protected passw as htmlInputText
protected UserID as htmlInputText
protected ModAspNG as checkbox
protected ModAsp as checkbox
etc.

But what do I do about a User Control on the original page, i.e.
<%@ Register TagPrefix="CBBMail" TagName="SendListMail"
Src="/CharlesTeam/BrianBilbro/common/UserControls/SendListMail.ascx" %>

which is used on the page ala:
<CBBMail:SendListMail id="ListMailForm" runat="server"/>

How do I declare it? i.e.
protected listmailform as ???????

If I leave it at the page level I eventually get the following error:
The name 'ListMailForm' is not declared.

Declaring it as object (a move of desparation) does not work.

At the code that registers its events it throws an error of course:

AddHandler ListMailForm.SentMessage , AddressOf evntMailForm_SentMessage
AddHandler ListMailForm.CancelMessage , AddressOf
evntMailForm_CancelMessage

Ala:
http://docs.learnasp.com/quickstart/aspplus/doc/webpagelets.aspx#program

I tried

Attempt A:
Adding <%@ Control ClassName="SendListMail" %> to the .ascx file
Dim LMF as Control loadControl("/CharlesTeam/BrianBilbro/common/UserControls/SendListMail.ascx"
)
and using Ctype(LMF,SendListMail) everywhere the control was
referenced. That was not the answer. Type is not defined: 'SendListMail'

Attempt B:
An attempt to add LMF to page ala:
Controls.Add (LMF)
results in error: "Expected either a variable, constant, Enum, Type, or
procedural declaration"

I have received other suggestions that I was not clear how to implement
and left me scratching my head.

Suggestion #1
In order to access the code, I believe you will have to compile the user
control code, or at least move it to its own vb or cs file like you showed
at http://www.learnasp.com/freebook/syntax/objectvb1.aspx, (although I
have never personally left it in a vb or cs file, I would guess it should
work).
Once compiled (and the namespace has been imported) you will be able to
reference is via traditional methods:
protected listmailform as SendListMail

Suggestion #2
Ok, here's what I've tried and what works. The way I have referenced UCs
was by either:
1. In an .aspx or .ascx page and just used the @ reference and refered to
the control as ASP.ControlPage_ascx
2. Or I referenced in a visual studio asp.net project and in the code
behind page. In that case you just import the project namespace in your
codebehind and then you can reference the control like so:
Imports MyProjectNamespace
......code....
Protected WithEvents MyControlInstances As MyProjectNamespace.MyControl
I have attached a simple VS.NET project that demos this.
but..but..but...what I haven't done is reference a user control is a
code-behind that is *not* precompiled (VS.net precompiles the codebehind).
This appears to be your situation. And it might not be possible to reference
it in the code-behind (at least with beta2). I haven't worked a whole lot on
this though. I tried a few things but couldn't get it to work. What I might
be able to do is precompile the SendMailForm User Control and put the DLL in
the bin directory. Then you should be able to reference it then. I'll let
you know when I get that (and probably a test page with it). |
[aspngescalate] member Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT
Reply to this message...
 
    
Brian Bilbro (VIP)
----- Original Message -----
From: "Charles M. Carroll" <Click here to reveal e-mail address>
Sent: Tuesday, January 01, 2002 7:16 PM

[Original message clipped]

I'm still holding out hope that it is possible too. I suspect a lot of this
will depend upon how asp.net compiles the source code it generates (if
asp.net tries to compile code behinds before .aspx or .ascx then I suspect
it won't be possible unless this gets/is fixed for RTM).

It seems weird that a user control can referenced in a .aspx or .ascx page
but that the same user control can't referenced in a code-behind that uses
the "src" attribute (ie. non-compiled codebehind project ala vs.net). :(

--
Brian

Reply to this message...
 
    
Jeff Widmer
I think you need to have the ascx inherit from a code-behind so that your
aspx code-behind has something to declare.

You'll have to create a sendlistmail.vb class and place all of the script
block in there. Something like the following....

Namespace Charles
Public Class CSendListMail
Inherits System.Web.UI.UserControl

Protected WithEvents SendMsg as System.Web.UI.WebControls.Button
Protected WithEvents Cancel as System.Web.UI.WebControls.Button

'Declare the other HTML elements here such as labels, etc.
' Protected lblSomething as System.Web.UI.WebControls.Label

Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler

Public Property ListName As String
Get
Return _Title
End Get
Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Private Sub SendMsg_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles SendMsg.Click
... code ....
End Sub

Private Sub Cancel_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Cancel.Click
... code ....
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String, _
strToEmail as string, strCC As String, strBCC As String, _
strSubject As String, strBody As String )
... code ...
End Sub

End Class
End Namespace

Then compile this class file like you would any other code-behind and then
make your ascx file inherit from this class.
<%@ Control ClassName="SendListMail" Inherits="Charles.CSendListMail" %>

Now you should be able to declare ascx code-behind class in the aspx
code-behind like:

Protected WithEvents ascxSendListMail as Charles.CSendListMail

-----Original Message-----
From: Charles M. Carroll [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 8:55 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

At 08:36 PM 1/1/2002 -0500, you wrote:

Is the SendListMail.ascx inheriting from a code-behind file also? Or does
it only include script blocks?

Can you post some of the SendListMail.ascx file?

No it is NOT inheriting/Code-Behind.

Here is a stripped down version of .ascx

Keep in mind it works great before CB comes into play.

.ascx file below:

<%@ Control ClassName="SendListMail" %>
<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler
Sub Page_Load(Src As Object, E As EventArgs)
End Sub

Public Property ListName As String
Get
Return _Title
End Get

Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Sub SendMsg_Click( S As Object, E As EventArgs )
... code ....
End Sub
'-------------------------------------------------------------
Sub Cancel_Click( S As Object, E As EventArgs )
... code ...
RaiseEvent CancelMessage(S,E)
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String,
strToEmail as string, strCC As String, strBCC As String, strSubject As
String, strBody As String )
... code ...
End Sub

.... a whole bunch of HTML .... | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

Reply to this message...
 
    
Alex Lowe
To save people time, Charles (smack me if I'm wrong here) does not want
a solution that

a)requires code behind for the user control (sorry Jeff)
or
b)uses reflection in the codebehind of the .aspx page.

Both of those have already been proposed and are not acceptable.

The idea here is that there is an existing .ascx file and the perfect
solution would require zero or very very few modifications to the .ascx
page/file. So, the solution would allow the properties/methods/events of
a user control (all code, script blocks and all, in a .ascx file) to be
accessed in the codebehind of a .aspx file.

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jeff Widmer [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 8:30 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

I think you need to have the ascx inherit from a code-behind so that
your aspx code-behind has something to declare.

You'll have to create a sendlistmail.vb class and place all of the
script block in there. Something like the following....

Namespace Charles
Public Class CSendListMail
Inherits System.Web.UI.UserControl

Protected WithEvents SendMsg as System.Web.UI.WebControls.Button
Protected WithEvents Cancel as System.Web.UI.WebControls.Button

'Declare the other HTML elements here such as labels, etc.
' Protected lblSomething as System.Web.UI.WebControls.Label

Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler

Public Property ListName As String
Get
Return _Title
End Get
Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Private Sub SendMsg_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles SendMsg.Click
... code ....
End Sub

Private Sub Cancel_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Cancel.Click
... code ....
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String, _
strToEmail as string, strCC As String, strBCC As String, _
strSubject As String, strBody As String )
... code ...
End Sub

End Class
End Namespace

Then compile this class file like you would any other code-behind and
then make your ascx file inherit from this class. <%@ Control
ClassName="SendListMail" Inherits="Charles.CSendListMail" %>

Now you should be able to declare ascx code-behind class in the aspx
code-behind like:

Protected WithEvents ascxSendListMail as Charles.CSendListMail

-----Original Message-----
From: Charles M. Carroll [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 8:55 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

At 08:36 PM 1/1/2002 -0500, you wrote:

Is the SendListMail.ascx inheriting from a code-behind file also? Or
does it only include script blocks?

Can you post some of the SendListMail.ascx file?

No it is NOT inheriting/Code-Behind.

Here is a stripped down version of .ascx

Keep in mind it works great before CB comes into play.

.ascx file below:

<%@ Control ClassName="SendListMail" %>
<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As
System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler
Sub Page_Load(Src As Object, E As EventArgs)
End Sub

Public Property ListName As String
Get
Return _Title
End Get

Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Sub SendMsg_Click( S As Object, E As EventArgs )
... code ....
End Sub
'-------------------------------------------------------------
Sub Cancel_Click( S As Object, E As EventArgs )
... code ...
RaiseEvent CancelMessage(S,E)
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String,
strToEmail as string, strCC As String, strBCC As String, strSubject As
String, strBody As String )
... code ...
End Sub

.... a whole bunch of HTML .... | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

Reply to this message...
 
    
Brian Bilbro (VIP)
----- Original Message -----
From: "Alex Lowe" <Click here to reveal e-mail address>
Sent: Tuesday, January 01, 2002 10:44 PM

> a)requires code behind for the user control (sorry Jeff)

It's not so much as that as he doesn't want to precompile (I think :). I
don't think he would mind if the user control also had a code-behind (in
fact, that is the direction he is going with his aspx page). The problem is
he doesn't want "precompile". I believe Charles likes the good ol' days of
opening the source on the server and saving it (this doesn't require any
compiling sofware on client, etc...)...And I don't blame him....that model
works very well.

--
Brian

Reply to this message...
 
    
Brian Bilbro (VIP)
----- Original Message -----
From: "Jeff Widmer" <Click here to reveal e-mail address>
Sent: Tuesday, January 01, 2002 9:29 PM

[Original message clipped]

That's the problem...he doesn't want to precompile (if we have to start
precompiling everything then why have the on-the-fly compile option? :).

--
Brian

Reply to this message...
 
    
Jeff Widmer
Sorry. I don't have an answer that doesn't involve code-behind.
-Jeff

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 10:44 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

To save people time, Charles (smack me if I'm wrong here) does not want
a solution that

a)requires code behind for the user control (sorry Jeff)
or
b)uses reflection in the codebehind of the .aspx page.

Both of those have already been proposed and are not acceptable.

The idea here is that there is an existing .ascx file and the perfect
solution would require zero or very very few modifications to the .ascx
page/file. So, the solution would allow the properties/methods/events of
a user control (all code, script blocks and all, in a .ascx file) to be
accessed in the codebehind of a .aspx file.

Alex - AspFriends.com Moderation Team

ASP.NET Tips/Examples: http://aspalliance.com/aldotnet

-----Original Message-----
From: Jeff Widmer [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 8:30 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

I think you need to have the ascx inherit from a code-behind so that
your aspx code-behind has something to declare.

You'll have to create a sendlistmail.vb class and place all of the
script block in there. Something like the following....

Namespace Charles
Public Class CSendListMail
Inherits System.Web.UI.UserControl

Protected WithEvents SendMsg as System.Web.UI.WebControls.Button
Protected WithEvents Cancel as System.Web.UI.WebControls.Button

'Declare the other HTML elements here such as labels, etc.
' Protected lblSomething as System.Web.UI.WebControls.Label

Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler

Public Property ListName As String
Get
Return _Title
End Get
Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Private Sub SendMsg_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles SendMsg.Click
... code ....
End Sub

Private Sub Cancel_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Cancel.Click
... code ....
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String, _
strToEmail as string, strCC As String, strBCC As String, _
strSubject As String, strBody As String )
... code ...
End Sub

End Class
End Namespace

Then compile this class file like you would any other code-behind and
then make your ascx file inherit from this class. <%@ Control
ClassName="SendListMail" Inherits="Charles.CSendListMail" %>

Now you should be able to declare ascx code-behind class in the aspx
code-behind like:

Protected WithEvents ascxSendListMail as Charles.CSendListMail

-----Original Message-----
From: Charles M. Carroll [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 01, 2002 8:55 PM
To: aspngescalate
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

At 08:36 PM 1/1/2002 -0500, you wrote:

Is the SendListMail.ascx inheriting from a code-behind file also? Or
does it only include script blocks?

Can you post some of the SendListMail.ascx file?

No it is NOT inheriting/Code-Behind.

Here is a stripped down version of .ascx

Keep in mind it works great before CB comes into play.

.ascx file below:

<%@ Control ClassName="SendListMail" %>
<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
Private _Title As String
'------------------------------------------------------------
'--- Raised Events
'------------------------------------------------------------
Delegate Sub EventHandler(sender As Object, e As
System.EventArgs)
Public Event SentMessage As EventHandler
Public Event CancelMessage As EventHandler
Sub Page_Load(Src As Object, E As EventArgs)
End Sub

Public Property ListName As String
Get
Return _Title
End Get

Set
_Title = value
MailTitle.Text = ": " & value
End Set
End Property

Sub SendMsg_Click( S As Object, E As EventArgs )
... code ....
End Sub
'-------------------------------------------------------------
Sub Cancel_Click( S As Object, E As EventArgs )
... code ...
RaiseEvent CancelMessage(S,E)
End Sub

Sub SendMailMsg( strFromName As String, strFromEmail As String,
strToEmail as string, strCC As String, strBCC As String, strSubject As
String, strBody As String )
... code ...
End Sub

.... a whole bunch of HTML .... | [aspngescalate] member
Click here to reveal e-mail address = YOUR ID |
http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

Reply to this message...
 
    
dave wanta (VIP)
take a look at
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=108
and
http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=113

I believe this will get you started...

Cheers!
dave wanta
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.123aspx.com
The Largest ASP.NET Web Directory!
Find the latest ASP.NET resources --
Subscribe to our newsletter!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Brian Bilbro" <Click here to reveal e-mail address>
To: "aspngescalate" <Click here to reveal e-mail address>
Sent: Tuesday, January 01, 2002 8:52 PM
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

[Original message clipped]

Reply to this message...
 
    
Jeff Widmer
Charles,
I think I got it. There is no precompiled objects and the ascx file is
referenced in the aspx code-behind so I think that solves the problem. I
created a simple sample to prove my idea.

There are three files involved, test.aspx, test.vb, and _control.ascx
(complete code is below). The test.aspx file has a code-behind (test.vb)
that gets compiled on the fly (using the src attribute). The _control.ascx
file also gets compiled on the fly (also using the src attribute). The
test.vb is the code-behind for both the aspx and the ascx file. It contains
two classes, one for the aspx file and one for the ascx file. And, as you
can see below, the ascx control is being created and referenced in the aspx
code-behind:
Protected WithEvents ascxControl as Charles.C_control

I think that the entire file, test.vb, is compiled first and then the ascx
code-behind class is available in the aspx code-behind.

Let me know if this answers your question.
-Jeff

FILE: test.aspx
<%@ Page Language="vb" src="test.vb" Inherits="Charles.CTest"%>
<%@ Register TagPrefix="JJJ" TagName="Control" Src="_control.ascx" %>
<html>
<body>
    <form runat=server>
    <asp:label id="lblTest" runat=server />
    <asp:button id="cmdTest" runat=server text="test" />
    <JJJ:Control runat="server" ID="ascxControl"/>
    </form>
</body>

FILE: test.vb
Namespace Charles
Public Class CTest
Inherits System.Web.UI.Page

Protected WithEvents cmdTest as System.Web.UI.WebControls.Button
Protected lblTest as System.Web.UI.WebControls.Label
Protected WithEvents ascxControl as Charles.C_control

Private Sub cmdTest_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles cmdTest.Click
lblTest.Text = "Hello from codeBehind"

ascxControl.message = "Clicked the aspx button"
End Sub

End Class

Public Class C_control
Inherits System.Web.UI.UserControl

Protected WithEvents cmdControlTest as System.Web.UI.WebControls.Button
Protected lblControlTest as System.Web.UI.WebControls.Label

Public Property message As String
Get
Return cstr(ViewState("message"))
End Get
Set
ViewState("message") = value
End Set
End Property

Private Sub cmdControlTest_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles cmdControlTest.Click
lblControlTest.Text = message
End Sub

End Class
End Namespace

FILE: _control.ascx
<%@ Control Language="vb" Inherits="Charles.C_control" src="test.vb"%>

<table bgcolor=Yellow>
    <tr>
    <td align="center">
        <asp:Label ID="lblControlTest" Runat="server" text="here" />
        <asp:Button ID="cmdControlTest" Runat="server" text="Control Button" />
    </td>
    </tr>
</table>

Reply to this message...
 
    
Steven A Smith (VIP)
To my knowledge,
(a) and (b) are the only two (known) solutions to this problem that have
come to light in the last year. This has been something of a FAQ since
about a year ago. If there is another solution, perhaps Scott or Susan
knows it?

Steve

----- Original Message -----
From: "Alex Lowe" <Click here to reveal e-mail address>
To: "aspngescalate" <Click here to reveal e-mail address>
Sent: Tuesday, January 01, 2002 10:44 PM
Subject: [aspngescalate] RE: User Controls and Form Inheritance - How to
Declare Them?

[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.EventHandler
System.Web.UI.Page
System.Web.UI.UserControl
System.Web.UI.WebControls.Button
System.Web.UI.WebControls.Label




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com