Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Code-Behind Pain in the Behind!

Reply
Thread Tools

Code-Behind Pain in the Behind!

 
 
Daniel Manes
Guest
Posts: n/a
 
      06-10-2005
Okay, here are the facts ma'am (or mister):

1. I have a user control called "Header" and a main page called
"ReportMatch".
2. I've written "code-behinds" for both the user control and the main
page.
3. This means four files: Ladder.ascx, Ladder.ascx.vb,
ReportMatch.aspx, and ReportMatch.aspx.vb.
4. None of this stuff is precompiled, and I would prefer not to have to
mess with precompiling and dll's and all that jazz (and I don't have
VS.NET).
5. I have Option Strict turned on.
6. I can get the Header to show up in ReportMatch (yay!), but if I try
to declare a variable in the ReportMatch code-behind as type Header, I
get the error "BC30002: Type 'Header' is not defined" (boo!).

So, my question:
Is there any way to get this error to stop occurring? Please tell me
there is. I'm going crazy here!

Here are some code snippets (all in VB.NET):

********** from Ladder.ascx **********
<%@ Control Language="VB" Explicit="True" Strict="True" Debug="True"
Src="Ladder.ascx.vb" %>
<table> ... some links ... </table>

********** from Ladder.ascx.vb **********
Option Explicit
Option Strict
Imports System, System.Configuration, System.Data, System.Data.Odbc,
System.Web.UI, System.Web.UI.WebControls
Public Class Header
Inherits UserControl
Public LogInLink As HyperLink
'A few more declarations like this -- snipped
Sub InitConnectObj
Dim ConnectStr As String
ConnectStr = ConfigurationSettings.AppSettings("ConnectStr")
ConnectObjG.ConnectionString = ConnectStr
End Sub
'Another method -- snipped
End Class

********** from ReportMatch.ascx **********
<%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
Src="ReportMatch.aspx.vb" %>
<%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
<html><head> ... </head>
<body><form runat="server">
<Ladder:Header ID="HeaderCtrl" runat="server" />
<table> ... some stuff ... </table>
.... some custom validator tags ...
</form></body></html>

********** from ReportMatch.ascx.vb **********
Option Explicit
Option Strict
Imports Microsoft.VisualBasic, System, System.Configuration,
System.Collections, System.Data, System.Data.Odbc, System.Math,
System.Web.UI, System.Web.UI.WebControls
Public Class ReportMatch
Inherits Page
Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx.vb"),
Header) 'This generates the error "BC30002: Type 'Header' is not
defined"!!!
Public DateCtrl As Calendar
'A few more declarations like this -- snipped
Sub Page_Load(Sender As Object, E As EventArgs)
HeaderCtrl.InitConnectObj() 'If I try to declare HeaderCtrl As Type
Control or UserControl, this doesn't work because InitConnectObj is not
a method of either of those classes.
'Some other stuff -- snipped
End Sub
'Several methods and validation handlers -- snipped
End Class

I've scoured this newsgroup and Google and tried seemingly everything
(except precompiling into dll's, which I hope I don't have to do), and
I just can't get this thing working.

Thanks in advance! (or TIA! if you prefer your thank you's in acronym
form)

-Dan

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UnlhbiBIYW5jb2Nr?=
Guest
Posts: n/a
 
      06-10-2005
Try placing the classes within the same namespace. Your code should work
fine at that point.

-Ryan

"Daniel Manes" wrote:

> Okay, here are the facts ma'am (or mister):
>
> 1. I have a user control called "Header" and a main page called
> "ReportMatch".
> 2. I've written "code-behinds" for both the user control and the main
> page.
> 3. This means four files: Ladder.ascx, Ladder.ascx.vb,
> ReportMatch.aspx, and ReportMatch.aspx.vb.
> 4. None of this stuff is precompiled, and I would prefer not to have to
> mess with precompiling and dll's and all that jazz (and I don't have
> VS.NET).
> 5. I have Option Strict turned on.
> 6. I can get the Header to show up in ReportMatch (yay!), but if I try
> to declare a variable in the ReportMatch code-behind as type Header, I
> get the error "BC30002: Type 'Header' is not defined" (boo!).
>
> So, my question:
> Is there any way to get this error to stop occurring? Please tell me
> there is. I'm going crazy here!
>
> Here are some code snippets (all in VB.NET):
>
> ********** from Ladder.ascx **********
> <%@ Control Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="Ladder.ascx.vb" %>
> <table> ... some links ... </table>
>
> ********** from Ladder.ascx.vb **********
> Option Explicit
> Option Strict
> Imports System, System.Configuration, System.Data, System.Data.Odbc,
> System.Web.UI, System.Web.UI.WebControls
> Public Class Header
> Inherits UserControl
> Public LogInLink As HyperLink
> 'A few more declarations like this -- snipped
> Sub InitConnectObj
> Dim ConnectStr As String
> ConnectStr = ConfigurationSettings.AppSettings("ConnectStr")
> ConnectObjG.ConnectionString = ConnectStr
> End Sub
> 'Another method -- snipped
> End Class
>
> ********** from ReportMatch.ascx **********
> <%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="ReportMatch.aspx.vb" %>
> <%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
> <html><head> ... </head>
> <body><form runat="server">
> <Ladder:Header ID="HeaderCtrl" runat="server" />
> <table> ... some stuff ... </table>
> .... some custom validator tags ...
> </form></body></html>
>
> ********** from ReportMatch.ascx.vb **********
> Option Explicit
> Option Strict
> Imports Microsoft.VisualBasic, System, System.Configuration,
> System.Collections, System.Data, System.Data.Odbc, System.Math,
> System.Web.UI, System.Web.UI.WebControls
> Public Class ReportMatch
> Inherits Page
> Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx.vb"),
> Header) 'This generates the error "BC30002: Type 'Header' is not
> defined"!!!
> Public DateCtrl As Calendar
> 'A few more declarations like this -- snipped
> Sub Page_Load(Sender As Object, E As EventArgs)
> HeaderCtrl.InitConnectObj() 'If I try to declare HeaderCtrl As Type
> Control or UserControl, this doesn't work because InitConnectObj is not
> a method of either of those classes.
> 'Some other stuff -- snipped
> End Sub
> 'Several methods and validation handlers -- snipped
> End Class
>
> I've scoured this newsgroup and Google and tried seemingly everything
> (except precompiling into dll's, which I hope I don't have to do), and
> I just can't get this thing working.
>
> Thanks in advance! (or TIA! if you prefer your thank you's in acronym
> form)
>
> -Dan
>
>

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      06-10-2005
Two things:

1) LoadControl takes a relative path to a ASCX file (not a .VB file).
2) You can use the <%@ Reference Control="foo.ascx" %> syntax to add a reference
to the user control's assembly.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> Okay, here are the facts ma'am (or mister):
>
> 1. I have a user control called "Header" and a main page called
> "ReportMatch".
> 2. I've written "code-behinds" for both the user control and the main
> page.
> 3. This means four files: Ladder.ascx, Ladder.ascx.vb,
> ReportMatch.aspx, and ReportMatch.aspx.vb.
> 4. None of this stuff is precompiled, and I would prefer not to have
> to
> mess with precompiling and dll's and all that jazz (and I don't have
> VS.NET).
> 5. I have Option Strict turned on.
> 6. I can get the Header to show up in ReportMatch (yay!), but if I try
> to declare a variable in the ReportMatch code-behind as type Header, I
> get the error "BC30002: Type 'Header' is not defined" (boo!).
> So, my question:
> Is there any way to get this error to stop occurring? Please tell me
> there is. I'm going crazy here!
> Here are some code snippets (all in VB.NET):
>
> ********** from Ladder.ascx **********
> <%@ Control Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="Ladder.ascx.vb" %>
> <table> ... some links ... </table>
> ********** from Ladder.ascx.vb **********
> Option Explicit
> Option Strict
> Imports System, System.Configuration, System.Data, System.Data.Odbc,
> System.Web.UI, System.Web.UI.WebControls
> Public Class Header
> Inherits UserControl
> Public LogInLink As HyperLink
> 'A few more declarations like this -- snipped
> Sub InitConnectObj
> Dim ConnectStr As String
> ConnectStr = ConfigurationSettings.AppSettings("ConnectStr")
> ConnectObjG.ConnectionString = ConnectStr
> End Sub
> 'Another method -- snipped
> End Class
> ********** from ReportMatch.ascx **********
> <%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="ReportMatch.aspx.vb" %>
> <%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
> <html><head> ... </head>
> <body><form runat="server">
> <Ladder:Header ID="HeaderCtrl" runat="server" />
> <table> ... some stuff ... </table>
> ... some custom validator tags ...
> </form></body></html>
> ********** from ReportMatch.ascx.vb **********
> Option Explicit
> Option Strict
> Imports Microsoft.VisualBasic, System, System.Configuration,
> System.Collections, System.Data, System.Data.Odbc, System.Math,
> System.Web.UI, System.Web.UI.WebControls
> Public Class ReportMatch
> Inherits Page
> Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx.vb"),
> Header) 'This generates the error "BC30002: Type 'Header' is not
> defined"!!!
> Public DateCtrl As Calendar
> 'A few more declarations like this -- snipped
> Sub Page_Load(Sender As Object, E As EventArgs)
> HeaderCtrl.InitConnectObj() 'If I try to declare HeaderCtrl As Type
> Control or UserControl, this doesn't work because InitConnectObj is
> not
> a method of either of those classes.
> 'Some other stuff -- snipped
> End Sub
> 'Several methods and validation handlers -- snipped
> End Class
> I've scoured this newsgroup and Google and tried seemingly everything
> (except precompiling into dll's, which I hope I don't have to do), and
> I just can't get this thing working.
>
> Thanks in advance! (or TIA! if you prefer your thank you's in acronym
> form)
>
> -Dan
>




 
Reply With Quote
 
danthman
Guest
Posts: n/a
 
      06-10-2005
Hi Ryan,

That sounds like it might help, but I'm not quite sure how to pull that
off. Could I trouble you to send a little more info?

Thanks,

-Dan

 
Reply With Quote
 
danthman
Guest
Posts: n/a
 
      06-10-2005
Hi Brock,

I tried both of those"two things," and I crossed my finger too, but I
still get the same confounded error "BC30002 Type 'Header' is not
defined." Here's how my code looks now:

********** ReportMatch.aspx **********
<%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
Inherits="ReportMatch" Src="ReportMatch.aspx.vb" %>
<%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
<%@ Reference Control="Ladder.ascx" %>

********** ReportMatch.aspx.vb **********
Public Class ReportMatch
Inherits Page
Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx"),
Header)

Any other thoughts?

Thanks!

-Dan

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      06-10-2005
Ohh, sorry. I was being a moron -- for some reason I was assuming your code
for the ASPX was inline with the ASPX itself (instead of codebehind).

Yeah, I think you're out of luck. The codebehinds for the ASPXs are compiled
at a different time than the codebehind for ASCXs, so that class (your ASCX
codebehind) isn't in the compilation context. If you did move the code from
your ASPX's codebehind into the ASPX itself (inside a <script runat=server>
block) then it'd work.

If you look at using WebMatrix as an editor then its codemodel is all code
inside (as opposed to codebehind) and this problem dosn't arise. Here's the
download if you don't have it already:

http://www.asp.net/webmatrix/download.aspx?tabindex=4

-Brock
DevelopMentor
http://staff.develop.com/ballen



> Hi Brock,
>
> I tried both of those"two things," and I crossed my finger too, but I
> still get the same confounded error "BC30002 Type 'Header' is not
> defined." Here's how my code looks now:
>
> ********** ReportMatch.aspx **********
> <%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
> Inherits="ReportMatch" Src="ReportMatch.aspx.vb" %>
> <%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
> <%@ Reference Control="Ladder.ascx" %>
> ********** ReportMatch.aspx.vb **********
> Public Class ReportMatch
> Inherits Page
> Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx"),
> Header)
> Any other thoughts?
>
> Thanks!
>
> -Dan
>




 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      06-10-2005
you are not going to like this.

if you were using vs.net, it compiles all the codebehinds into a single dll.
therefore you can reference other classes. to duplicate this behavioor, you
need to remove the "src=" attribute from the aspx pages, and use the vb.net
compiler, to compile all the codebehinds into a single dll, and place in the
bin.

your only other option is late binding

-- bruce (sqlwork.com)





"Daniel Manes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Okay, here are the facts ma'am (or mister):
>
> 1. I have a user control called "Header" and a main page called
> "ReportMatch".
> 2. I've written "code-behinds" for both the user control and the main
> page.
> 3. This means four files: Ladder.ascx, Ladder.ascx.vb,
> ReportMatch.aspx, and ReportMatch.aspx.vb.
> 4. None of this stuff is precompiled, and I would prefer not to have to
> mess with precompiling and dll's and all that jazz (and I don't have
> VS.NET).
> 5. I have Option Strict turned on.
> 6. I can get the Header to show up in ReportMatch (yay!), but if I try
> to declare a variable in the ReportMatch code-behind as type Header, I
> get the error "BC30002: Type 'Header' is not defined" (boo!).
>
> So, my question:
> Is there any way to get this error to stop occurring? Please tell me
> there is. I'm going crazy here!
>
> Here are some code snippets (all in VB.NET):
>
> ********** from Ladder.ascx **********
> <%@ Control Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="Ladder.ascx.vb" %>
> <table> ... some links ... </table>
>
> ********** from Ladder.ascx.vb **********
> Option Explicit
> Option Strict
> Imports System, System.Configuration, System.Data, System.Data.Odbc,
> System.Web.UI, System.Web.UI.WebControls
> Public Class Header
> Inherits UserControl
> Public LogInLink As HyperLink
> 'A few more declarations like this -- snipped
> Sub InitConnectObj
> Dim ConnectStr As String
> ConnectStr = ConfigurationSettings.AppSettings("ConnectStr")
> ConnectObjG.ConnectionString = ConnectStr
> End Sub
> 'Another method -- snipped
> End Class
>
> ********** from ReportMatch.ascx **********
> <%@ Page Language="VB" Explicit="True" Strict="True" Debug="True"
> Src="ReportMatch.aspx.vb" %>
> <%@ Register TagPrefix="Ladder" TagName="Header" Src="Ladder.ascx" %>
> <html><head> ... </head>
> <body><form runat="server">
> <Ladder:Header ID="HeaderCtrl" runat="server" />
> <table> ... some stuff ... </table>
> ... some custom validator tags ...
> </form></body></html>
>
> ********** from ReportMatch.ascx.vb **********
> Option Explicit
> Option Strict
> Imports Microsoft.VisualBasic, System, System.Configuration,
> System.Collections, System.Data, System.Data.Odbc, System.Math,
> System.Web.UI, System.Web.UI.WebControls
> Public Class ReportMatch
> Inherits Page
> Public HeaderCtrl As Header = CType(LoadControl("Ladder.ascx.vb"),
> Header) 'This generates the error "BC30002: Type 'Header' is not
> defined"!!!
> Public DateCtrl As Calendar
> 'A few more declarations like this -- snipped
> Sub Page_Load(Sender As Object, E As EventArgs)
> HeaderCtrl.InitConnectObj() 'If I try to declare HeaderCtrl As Type
> Control or UserControl, this doesn't work because InitConnectObj is not
> a method of either of those classes.
> 'Some other stuff -- snipped
> End Sub
> 'Several methods and validation handlers -- snipped
> End Class
>
> I've scoured this newsgroup and Google and tried seemingly everything
> (except precompiling into dll's, which I hope I don't have to do), and
> I just can't get this thing working.
>
> Thanks in advance! (or TIA! if you prefer your thank you's in acronym
> form)
>
> -Dan
>



 
Reply With Quote
 
danthman
Guest
Posts: n/a
 
      06-10-2005
Thanks, Brock.

I actually have WebMatrix on my machine but I've been using Dreamweaver
because it at least has an Intellisense-like feature for constructing
tags.

Also, I originally had all my html and scripting on one aspx page, but
things started to get difficult to manage. Moving the code into a
code-behind file made everything a lot easier to work with, except for
that little issue of it *not working*!

So, maybe I should just bite the bullet and learn how to pre-compile
the user control. Either that, or just stick everything back into one
aspx file again.

-Dan

 
Reply With Quote
 
danthman
Guest
Posts: n/a
 
      06-10-2005
Hey Bruce,

Thanks for the info. Is "late binding" something I should be afraid of?
I'm not really up on how to do it with VB.NET. Any chance you could
send over a code snippet?

Thanks,

-Dan

 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      06-10-2005
> I actually have WebMatrix on my machine but I've been using Dreamweaver
> because it at least has an Intellisense-like feature for constructing
> tags.


DW and .net just don't go great together. I struggled for a while with it.
Finally broke down and went with VS.net.

IMHO, ASP.net and VS.net are designed to need each other to be productive.
I'm not necessarily happy with that, but it's simply the way MS went with
it.

> So, maybe I should just bite the bullet and learn how to pre-compile
> the user control. Either that, or just stick everything back into one
> aspx file again.


I'd suggest using code inline or going with VS.net for codebehind.

-Darrel


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Chronic Back Pain Michael MCSD 0 04-02-2006 02:43 AM
Chronic Back Pain Michael MCSE 0 04-02-2006 02:43 AM
Modelsim error: Cannot read output pain Olaf Petzold VHDL 12 12-23-2005 09:15 PM
Sorry to be such a pain Brent White ASP .Net 5 10-25-2005 09:15 PM
DropDownList Pain =?Utf-8?B?S1JN?= ASP .Net 2 05-25-2005 04:28 PM



Advertisments