代码背后的痛苦! [英] Code-Behind Pain in the Behind!

查看:68
本文介绍了代码背后的痛苦!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是事实ma''am(或先生):


1.我有一个名为Header的用户控件。还有一个名为

" ReportMatch"的主页。

2.我写过代码隐藏对于用户控件和主页面

页面。

3.这意味着四个文件:Ladder.ascx,Ladder.ascx.vb,

ReportMatch.aspx和ReportMatch.aspx.vb。

4.这些东西都不是预先编译的,我宁愿不要使用预编译和dll搞乱
's和所有那些爵士乐(我没有

VS.NET)。

5.我已经选择了Option Strict。

6.我可以在ReportMatch中显示Header(yay!),但如果我尝试使用
在ReportMatch代码隐藏中声明一个变量作为类型Header,我

得到错误BC30002:类型''标题''未定义 (嘘!)。


所以,我的问题:

有没有办法让这个错误停止发生?请告诉我

有。我在这里疯了!


以下是一些代码片段(全部在VB.NET中):


***** *****来自Ladder.ascx **********

<%@ Control Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"

Src =" Ladder.ascx.vb" %>

< table> ......一些链接...< / table>

来自Ladder.ascx.vb的
********** ********* *

选项明确

选项严格

导入系统,System.Configuration,System.Data,System.Data.Odbc,

System.Web.UI,System.Web.UI.WebControls

公共类标题

继承UserControl

Public LogInLink As HyperLink

''这样的一些声明 - 剪断了

Sub InitConnectObj

Dim ConnectStr As String

ConnectStr = ConfigurationSettings.AppSettings(" ConnectStr")

ConnectObjG.ConnectionString = ConnectStr

End Sub

''另一种方法 - 剪切

结束班

来自ReportMatch.ascx的
********** **********

<%@ Page Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"

Src =" ReportMatch.aspx.vb" %>

<%@ Register TagPrefix =" Ladder"标签名= QUOT;头" SRC =" Ladder.ascx" %>

< html>< head> ...< / head>

< body>< form runat =" server">

< Ladder:Header ID =" HeaderCtrl" RUNAT = QUOT;服务器" />

< table> ...一些东西...< / table>

....一些自定义验证器标签...

< / form>< / body> < / html>

来自ReportMatch.ascx.vb的
********** **********

选项显式

选项严格

导入Microsoft.VisualBasic,System,System.Configuration,

System.Collections,System.Data,System。 Data.Odbc,System.Math,

System.Web.UI,System.Web.UI.WebControls

公共类ReportMatch

继承页面

Public HeaderCtrl As Header = CType(LoadControl(" Ladder.ascx.vb"),

Header)''这会生成错误BC30002:Type''标题''不是

定义的'!!!

公共DateCtrl作为日历

''还有一些这样的声明 - 剪切

Sub Page_Load(发件人作为对象,E作为EventArgs)

HeaderCtrl.InitConnectObj()''如果我尝试将HeaderCtrl声明为类型

控制或UserControl,这不起作用,因为InitConnectObj不是这些类中任何一个的
a方法。

''其他一些东西 - 剪断了

结束Sub

''几种方法和验证处理程序 - 剪断

结束班


我已经搜查了这个新闻组和Google并试图看似所有的东西

(除了预编译成dll',我希望我不必这样做),并且

我无法得到这件事有效。


提前致谢! (或TIA!如果你更喜欢谢谢你的首字母缩略词

表格)


-Dan

解决方案

尝试将类放在同一名称空间中。你的代码应该可以工作

那时候罚款。


-Ryan


" Daniel Manes"写道:

好的,这是事实ma''am(或先生):

1.我有一个名为Header的用户控件。以及一个名为
ReportMatch的主页。
2.我写过代码隐藏用户控件和主页面。
3.这意味着四个文件:Ladder.ascx,Ladder.ascx.vb,
ReportMatch.aspx和ReportMatch.aspx.vb。
4.这些东西都不是预编译的,我宁愿不要乱用预编译和dll'以及所有那些爵士乐(我没有VS /> VS) .NET)。
5.我打开了Option Strict。
6.我可以在ReportMatch中显示Header(yay!),但如果我尝试
声明变量在ReportMatch代码隐藏中作为类型标题,我得到错误BC30002:类型''标题''未定义 (嘘!)。

所以,我的问题:
有没有办法让这个错误停止发生?请告诉我
有。我在这里疯了!

以下是一些代码片段(全部在VB.NET中):

来自Ladder的**********。 ascx **********
<%@ Control Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"
Src =" Ladder.ascx.vb" %>
< table> ......一些链接...< / table>

来自Ladder.ascx.vb的********** **********
Option Explicit
Option Strict
Imports System,System.Configuration,System.Data,System.Data.Odbc,
System.Web.UI,System.Web.UI.WebControls 公共类标题
继承UserControl
公共LogInLink作为HyperLink
''这样的一些声明 - 剪断了
Sub InitConnectObj
Dim ConnectStr As String
ConnectStr = ConfigurationSettings.AppSettings(" ConnectStr")
ConnectObjG.ConnectionString = ConnectStr
End Sub
''另一种方法 - 剪掉
End Class
<%@ Page Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"
Src =" ReportMatch.aspx.vb" %>
<%@ Register TagPrefix =" Ladder"标签名= QUOT;头" SRC =" Ladder.ascx" %>
< html>< head> ...< / head>
< body>< form runat =" server">
< Ladder:Header ID =" HeaderCtrl" RUNAT = QUOT;服务器" />
< table> ......一些东西......< / table>
....一些自定义验证器标签......
< / form>< / body>< / html>

**********来自ReportMatch.ascx.vb **********
选项明确
选项严格
进口微软。 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)''这会生成错误BC30002:Type ''标题''没有定义'!!!
公共DateCtrl作为日历
''这样的一些声明 - 剪断了
Sub Page_Load(Sender As Object, E作为EventArgs)
HeaderCtrl.InitConnectObj()''如果我尝试将HeaderCtrl声明为Type
Control或UserControl,这不起作用,因为InitConnectObj不是一种方法茨艾伦e类。
''其他一些东西 - 剪掉了
End Sub
''几种方法和验证处理程序 - 剪掉了
结束课

我已经搜索过这个新闻组和谷歌,并试图看似所有的东西
(除了预编译成dll',我希望我不必这样做),并且
我无法得到这件事有效。

提前致谢! (或TIA!如果你更喜欢谢谢你的缩写
形式)

-Dan


两件事:


1)LoadControl获取ASCX文件的相对路径(不是.VB文件)。

2)你可以使用<%@ Reference Control =" foo.ascx" %GT;语法为用户控件的程序集添加引用



-Brock

DevelopMentor
< a rel =nofollowhref =http://staff.develop.com/ballentarget =_ blank> http://staff.develop.com/ballen

好的,这是ma''am(或先生)的事实:

1.我有一个名为Header的用户控件。以及一个名为
ReportMatch的主页。
2.我写过代码隐藏用户控件和主页面。
3.这意味着四个文件:Ladder.ascx,Ladder.ascx.vb,
ReportMatch.aspx和ReportMatch.aspx.vb。
4.这些东西都不是预编译的,我宁愿没有
搞乱预编译和dll'以及所有那些爵士乐(我没有< (> VS.NET)。
5.我打开了Option Strict。
6.我可以在ReportMatch中显示Header(是的!),但是如果我尝试的话
在ReportMatch代码隐藏中声明一个变量作为类型标题,我得到错误BC30002:类型''标题''未定义 (嘘!)。
所以,我的问题:
有没有办法让这个错误停止发生?请告诉我
有。我在这里疯了!
这里有一些代码片段(全部在VB.NET中):

来自Ladder.ascx的********** *** *******
<%@ Control Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"
Src =" Ladder.ascx.vb" %>
< table> ...某些链接......< / table>
来自Ladder.ascx.vb的********** **********
选项明确<选项Strict
Imports System,System.Configuration,System.Data,System.Data.Odbc,
System.Web.UI,System.Web.UI.WebControls
Public Class Header
继承UserControl
公共LogInLink作为HyperLink
''这样的一些声明 - 剪断了
Sub InitConnectObj
Dim ConnectStr As String
ConnectStr = ConfigurationSettings .AppSettings(ConnectStr)
ConnectObjG.ConnectionString = ConnectStr
End Sub
''另一种方法 - 剪掉
结束班
****** ****来自ReportMatch.ascx **********
<%@ Page Language =" VB"明确= QUOT;真"严格= QUOT;真" Debug =" True"
Src =" ReportMatch.aspx.vb" %>
<%@ Register TagPrefix =" Ladder"标签名= QUOT;头" SRC =" Ladder.ascx" %>
< html>< head> ...< / head>
< body>< form runat =" server">
< Ladder:Header ID =" HeaderCtrl" RUNAT = QUOT;服务器" />
< table> ......一些东西...< / table>
...一些自定义验证器标签......
< / form>< / body>< / html>
**********来自ReportMatch.ascx.vb **********
选项明确
选项严格
导入Microsoft.VisualBasic,System,System .Configuration,
System.Collections,System.Data,System.Data.Odbc,System.Math,
System.Web.UI,System.Web.UI.WebControls
Public Class ReportMatch
继承页面
Public HeaderCtrl As Header = CType(LoadControl(" Ladder.ascx.vb"),
Header)''这会生成错误BC30002:输入''标题''没有定义!!!
公共DateCtrl作为日历
''这样的一些声明 - 剪断了
Sub Page_Load(Sender As Object,E As EventArgs)
HeaderCtrl.InitConnectObj()''如果我尝试将HeaderCtrl声明为类型
Control或UserControl,这不起作用,因为InitConnectObj不是
其中任何一种方法类es。
''其他一些东西 - 剪掉了
End Sub
''几种方法和验证处理程序 - 剪断了
End Class
我已经仔细研究了这个新闻组和谷歌并试图看似一切
(除了预编译成dll',我希望我不必这样做),并且
我不能让这个东西工作。

提前致谢! (或TIA!如果你更喜欢谢谢你的首字母缩略词
形式)

-Dan



嗨瑞恩,


这听起来似乎有所帮助,但我不太确定如何取消

。我可以麻烦你发一些信息吗?


谢谢,


-Dan


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

解决方案

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



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




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


这篇关于代码背后的痛苦!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆