有没有办法在其他用户控件中引用公共属性 [英] is there a way to refer to public properties in other user controls

查看:57
本文介绍了有没有办法在其他用户控件中引用公共属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我设置了一个包含2个用户控件的网页。


在经典的asp中,第一个完成所有的操作声明,第二个

使用了这些值,并且可以重置它。


到目前为止在ASP.Net中我看不到如何关联它们将起作用。


此用户控件定义属性:


<%@ Control ClassName =" topdcl" %>


< script language =" vb" runat =" server">

私有m_addressesstring为String =" adr,phone,zip,"


公共属性addressesstring()As String

获取


返回m_addressesstring


结束获取


套装(ByVal值为字符串)


m_addressesstring =价值


结束集


结束物业< br $>
Public Sub topdcl1()

addressesstring =" adr,phone,zip,"

End Sub


< / script>


此用户控件尝试访问公共属性''addressstring'',但

不能:


<%@ Control ClassName =" w" %>


< script language =" vb" runat =" server">


Public Sub w1()

my_topdcl.addressesstring = addressesstring& ",zip"

End Sub


< / script>


这是'的页面他们称之为:


<%@ Page Language =" VB" AutoEventWireup = QUOT假QUOT; CodeFile =" Default.aspx.vb"

Inherits =" _Default" %>


<%@ Register TagPrefix =" Utils"标签名= QUOT; topdcl" Src =" utils / topdcl_try.ascx"

%>


<%@ Register TagPrefix =" Utils"标签名= QUOT; W" SRC =" utils的/ w_try.ascx" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"

" ; http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns =" http:// www。 w3.org/1999/xhtml" >


< head runat =" server">


< title> Untitled Page< / title>


< / head>


< body>

< form id =" form1" runat =" server">


< div>

< / div>


< ; / form>


< Utils:topdcl id =" My_topdcl" runat =" server" />


< Utils:w id =" My_w" runat =" server" />

< / body>


< / html>


这里是这个页面背后的代码:


受保护的子Page_Load(ByVal发送者作为对象,ByVal e As System.EventArgs)

处理我.Load


My_topdcl.topdcl1()


My_w.w1()

结束子


我真的很感激任何帮助。


此时,我唯一的工作解决方案似乎是结合所有代码

成1个用户控件,而不是几个。然后变量可以在他们自己的类中引用

变量没有问题。


在经典的asp中,我使用包含所有昏暗的语句在第一个,

和后面的子程序包括。


谢谢。


Scott Baxter。

Hello,

I set up a web page with 2 user controls.

In classic asp, the first one did all the declarations, and the second one
used the values, and could reset it.

In ASP.Net so far I can''t see how to relate them so this will work.

This user control defines the properties:

<%@ Control ClassName="topdcl" %>

<script language="vb" runat="server">
Private m_addressesstring as String= "adr,phone,zip,"

Public Property addressesstring() As String
Get

Return m_addressesstring

End Get

Set(ByVal value As String)

m_addressesstring = Value

End Set

End Property
Public Sub topdcl1()
addressesstring= "adr,phone,zip,"
End Sub

</script>

This user control tries to access the public property ''addressstring'', but
can''t:

<%@ Control ClassName="w" %>

<script language="vb" runat="server">

Public Sub w1()
my_topdcl.addressesstring = addressesstring & ",zip"
End Sub

</script>

Here''s the page that calls them:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" TagName="topdcl" Src="utils/topdcl_try.ascx"
%>

<%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>
<form id="form1" runat="server">

<div>
</div>

</form>

<Utils:topdcl id="My_topdcl" runat="server"/>

<Utils:w id="My_w" runat="server"/>
</body>

</html>

Here''s the code behind for this page:

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

My_topdcl.topdcl1()

My_w.w1()
End Sub

I would really appreciate any help.

At this point, my only working solution seems to be to combine all the code
into 1 usercontrol, instead of having several. Then variables can refer to
variables in their own class with no problem.

In classic asp, I used includes with all the ''dim'' statements in the first,
and the subroutines in later includes.

Thanks.

Scott Baxter.

推荐答案

使用@reference指令

http://msdn2.microsoft.com/en-us/lib...5a(VS.80).aspx )可以访问

UCs类型,虽然不是100%确定它在这个

情况下会如何表现,因为他们(UC)需要引用每个类型其他但你可以试试。


-

Teemu Keiski

AspInsider,ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

网络搜索商店 < in ** @ websearchstore.comwrote in message

news:u4 **************** @ TK2MSFTNGP02.phx.gbl ...
Using @reference directive
(http://msdn2.microsoft.com/en-us/lib...5a(VS.80).aspx) makes the
UCs type accessible, although not 100% sure how it would behave in this
situation as they''d (UCs) need to reference each other but you can try.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Web Search Store" <in**@websearchstore.comwrote in message
news:u4****************@TK2MSFTNGP02.phx.gbl...

您好,


我设置了一个包含2个用户控件的网页。


在经典的asp中,第一个使用了所有的声明,第二个使用了这些值,并且可以重置它。


在ASP.Net中到目前为止,我无法看到如何将它们联系起来以便这样做。


这个用户控件定义了属性:


<% @ Control ClassName =" topdcl" %>


< script language =" vb" runat =" server">


私有m_addressesstring为String =" adr,phone,zip,"


公共属性addressesstring ()作为字符串


获取


返回m_addressesstring


结束获取


设定(ByVal值为字符串)


m_addressesstring =价值


结束集

结束物业


Public Sub topdcl1()


addressesstring =" adr,phone,zip,"


结束子


< / script>



此用户控制尝试访问公共财产''addressstring'',但

不能:


<%@ Control ClassName =" w" %>


< script language =" vb" runat =" server">


Public Sub w1()


my_topdcl.addressesstring = addressesstring& ",zip"


End Sub


< / script>


这里'是调用它们的页面:


<%@ Page Language =" VB" AutoEventWireup = QUOT假QUOT; CodeFile =" Default.aspx.vb"

Inherits =" _Default" %>


<%@ Register TagPrefix =" Utils" TagName =" topdcl"

Src =" utils / topdcl_try.ascx" %>


<%@ Register TagPrefix =" Utils"标签名= QUOT; W" SRC =" utils的/ w_try.ascx" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"

" ; http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns =" http:// www。 w3.org/1999/xhtml" >


< head runat =" server">


< title> Untitled Page< / title>


< / head>


< body>


< form id =" form1" ; runat =" server">


< div>


< / div>


< / form>


< Utils:topdcl id =" My_topdcl" runat =" server" />


< Utils:w id =" My_w" runat =" server" />


< / body>


< / html>

这里是这个页面背后的代码:


受保护的子Page_Load(ByVal发送者作为对象,ByVal e As

系统。 EventArgs)处理Me.Load


My_topdcl.topdcl1()


My_w.w1()


End Sub


我真的很感激任何帮助。


此时,我唯一的工作解决方案似乎是将所有的

代码转换为1个usercontrol,而不是几个。然后变量可以在他们自己的类中引用变量没有问题。


在经典的asp中,我使用了包含所有昏暗的语句首先是

,后面的子程序包括。


谢谢。


Scott Baxter。

Hello,

I set up a web page with 2 user controls.

In classic asp, the first one did all the declarations, and the second one
used the values, and could reset it.

In ASP.Net so far I can''t see how to relate them so this will work.

This user control defines the properties:

<%@ Control ClassName="topdcl" %>

<script language="vb" runat="server">
Private m_addressesstring as String= "adr,phone,zip,"

Public Property addressesstring() As String
Get

Return m_addressesstring

End Get

Set(ByVal value As String)

m_addressesstring = Value

End Set

End Property
Public Sub topdcl1()
addressesstring= "adr,phone,zip,"
End Sub

</script>

This user control tries to access the public property ''addressstring'', but
can''t:

<%@ Control ClassName="w" %>

<script language="vb" runat="server">

Public Sub w1()
my_topdcl.addressesstring = addressesstring & ",zip"
End Sub

</script>

Here''s the page that calls them:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" TagName="topdcl"
Src="utils/topdcl_try.ascx" %>

<%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>
<form id="form1" runat="server">

<div>
</div>

</form>

<Utils:topdcl id="My_topdcl" runat="server"/>

<Utils:w id="My_w" runat="server"/>
</body>

</html>

Here''s the code behind for this page:

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

My_topdcl.topdcl1()

My_w.w1()
End Sub

I would really appreciate any help.

At this point, my only working solution seems to be to combine all the
code into 1 usercontrol, instead of having several. Then variables can
refer to variables in their own class with no problem.

In classic asp, I used includes with all the ''dim'' statements in the
first, and the subroutines in later includes.

Thanks.

Scott Baxter.



非常感谢。


我会读的。


Scott

" Teemu Keiski" < jo **** @ aspalliance.comwrote in message

news:%2 ****************** @ TK2MSFTNGP06.phx.gbl。 ..
Thanks a lot.

I''ll read it.

Scott
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...

使用@reference指令

http://msdn2.microsoft.com/en-us/lib...5a(VS.80).aspx )可以访问

UCs类型,虽然不能100%确定它在这个

情况下会如何表现,因为他们(UC)需要互相参考但是你可以尝试。


-

Teemu Keiski

AspInsider,ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


网页搜索商店 < in ** @ websearchstore.comwrote in message

news:u4 **************** @ TK2MSFTNGP02.phx.gbl ...
Using @reference directive
(http://msdn2.microsoft.com/en-us/lib...5a(VS.80).aspx) makes the
UCs type accessible, although not 100% sure how it would behave in this
situation as they''d (UCs) need to reference each other but you can try.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Web Search Store" <in**@websearchstore.comwrote in message
news:u4****************@TK2MSFTNGP02.phx.gbl...

>您好,

我设置了一个包含2个用户控件的网页。

在经典的asp中,第一个一个人完成了所有的声明,第二个人使用了这些值,并且可以重置它。

在ASP.Net中到目前为止我看不到如何关联它们所以这将是这个用户控件定义了属性:

<%@ Control ClassName =" topdcl" %>

< script language =" vb" runat =" server">

私有m_addressesstring为String =" adr,phone,zip,"

公共属性addressesstring()As String

获取

返回m_addressesstring

结束获取

设置(ByVal值为字符串)

m_addressesstring =价值

结束集

结束财产

Public Sub topdcl1()

addressesstring =" adr,phone, zip,

End Sub

< / script>


此用户控件试图访问公共属性'' addressstring'',
但不能:

<%@ Control ClassName =" w" %>

< script language =" vb" runat =" server">

Public Sub w1()

my_topdcl.addressesstring = addressesstring& ",zip"

End Sub

< / script>

这是调用它们的页面:

<%@ Page Language =" VB" AutoEventWireup = QUOT假QUOT; CodeFile =" Default.aspx.vb"
Inherits =" _Default" %>

<%@ Register TagPrefix =" Utils" TagName =" topdcl"
Src =" utils / topdcl_try.ascx" %>

<%@ Register TagPrefix =" Utils"标签名= QUOT; W" SRC =" utils的/ w_try.ascx" %>

<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"
" http://www.w3 .org / TR / xhtml1 / DTD / xhtml1-transitional.dtd">

< html xmlns =" http://www.w3.org/1999/xhtml" >

< head runat =" server">

< title> Untitled Page< / title>

< / head>

< body>

< form id =" form1" runat =" server">

< div>

< / div>

< / form>

< Utils:topdcl id =" My_topdcl" runat =" server" />

< Utils:w id =" My_w" runat =" server" />

< / body>

< / html>

这里是代码背后的代码对于此页面:

受保护的子Page_Load(ByVal发送者作为对象,ByVal e As
System.EventArgs)处理Me.Load

My_topdcl.topdcl1()

My_w.w1()

End Sub

我真的很感激任何帮助。

此时,我的只有工作解决方案似乎是将所有的代码组合成1个用户控件,而不是几个。然后变量可以在他们自己的类中引用变量而没有问题。

在经典的asp中,我首先在
中使用了包含所有''dim''语句,以及后面的子程序包括。

谢谢。

Scott Baxter。

>Hello,

I set up a web page with 2 user controls.

In classic asp, the first one did all the declarations, and the second
one used the values, and could reset it.

In ASP.Net so far I can''t see how to relate them so this will work.

This user control defines the properties:

<%@ Control ClassName="topdcl" %>

<script language="vb" runat="server">
Private m_addressesstring as String= "adr,phone,zip,"

Public Property addressesstring() As String
Get

Return m_addressesstring

End Get

Set(ByVal value As String)

m_addressesstring = Value

End Set

End Property
Public Sub topdcl1()
addressesstring= "adr,phone,zip,"
End Sub

</script>

This user control tries to access the public property ''addressstring'',
but can''t:

<%@ Control ClassName="w" %>

<script language="vb" runat="server">

Public Sub w1()
my_topdcl.addressesstring = addressesstring & ",zip"
End Sub

</script>

Here''s the page that calls them:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" TagName="topdcl"
Src="utils/topdcl_try.ascx" %>

<%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>
<form id="form1" runat="server">

<div>
</div>

</form>

<Utils:topdcl id="My_topdcl" runat="server"/>

<Utils:w id="My_w" runat="server"/>
</body>

</html>

Here''s the code behind for this page:

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

My_topdcl.topdcl1()

My_w.w1()
End Sub

I would really appreciate any help.

At this point, my only working solution seems to be to combine all the
code into 1 usercontrol, instead of having several. Then variables can
refer to variables in their own class with no problem.

In classic asp, I used includes with all the ''dim'' statements in the
first, and the subroutines in later includes.

Thanks.

Scott Baxter.




4月21日,20:21,网络搜索商店 < i ... @ websearchstore.comwrote:
On 21 Apr, 20:21, "Web Search Store" <i...@websearchstore.comwrote:

您好,


我设置了一个包含2个用户的网页控制。


在经典的asp中,第一个执行所有声明,第二个使用值,并且可以重置它。


到目前为止在ASP.Net中我看不到如何关联它们以便这样做。


此用户控件定义属性:


<%@ Control ClassName =" topdcl" %>


< script language =" vb" runat =" server">


私有m_addressesstring为String =" adr,phone,zip,"


公共属性addressesstring ()作为字符串


获取


返回m_addressesstring


结束获取


设定(ByVal值为字符串)


m_addressesstring =价值


结束集

结束物业


Public Sub topdcl1()


addressesstring =" adr,phone,zip,"


结束子


< / script>


此用户控件尝试访问公共属性''addressstring'',但是

不能:


<%@ Control ClassName =" w" %>


< script language =" vb" runat =" server">


Public Sub w1()


my_topdcl.addressesstring = addressesstring& ",zip"


End Sub


< / script>


这里'是调用它们的页面:


<%@ Page Language =" VB" AutoEventWireup = QUOT假QUOT; CodeFile =" Default.aspx.vb"

Inherits =" _Default" %>


<%@ Register TagPrefix =" Utils"标签名= QUOT; topdcl" Src =" utils / topdcl_try.ascx"

%>


<%@ Register TagPrefix =" Utils"标签名= QUOT; W" SRC =" utils的/ w_try.ascx" %>


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN"

" http:/ /www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


< html xmlns =" http://www.w3.org/ 1999 / XHTML" >


< head runat =" server">


< title> Untitled Page< / title>


< / head>


< body>


< form id =" form1" ; runat =" server">


< div>


< / div>


< / form>


< Utils:topdcl id =" My_topdcl" runat =" server" />


< Utils:w id =" My_w" runat =" server" />


< / body>


< / html>

这里是这个页面背后的代码:


受保护的子Page_Load(ByVal发送者为对象,ByVal e As System.EventArgs)

Handles Me.Load


My_topdcl.topdcl1()


My_w.w1()


*结束子


*我真的很感激任何帮助。


此时,我唯一的工作解决方案似乎是结合起来将所有代码

分成1个用户控件,而不是几个。 *然后变量可以在他们自己的类中输入
变量没有问题。


在经典的asp中,我使用包含所有''dim''语句在第一个,

和后面的子程序包括。


谢谢。


Scott Baxter。
Hello,

I set up a web page with 2 user controls.

In classic asp, the first one did all the declarations, and the second one
used the values, and could reset it.

In ASP.Net so far I can''t see how to relate them so this will work.

This user control defines the properties:

<%@ Control ClassName="topdcl" %>

<script language="vb" runat="server">

Private m_addressesstring as String= "adr,phone,zip,"

Public Property addressesstring() As String

Get

Return m_addressesstring

End Get

Set(ByVal value As String)

m_addressesstring = Value

End Set

End Property

Public Sub topdcl1()

addressesstring= "adr,phone,zip,"

End Sub

</script>

This user control tries to access the public property ''addressstring'', but
can''t:

<%@ Control ClassName="w" %>

<script language="vb" runat="server">

Public Sub w1()

my_topdcl.addressesstring = addressesstring & ",zip"

End Sub

</script>

Here''s the page that calls them:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register TagPrefix="Utils" TagName="topdcl" Src="utils/topdcl_try.ascx"
%>

<%@ Register TagPrefix="Utils" TagName="w" Src="utils/w_try.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

</div>

</form>

<Utils:topdcl id="My_topdcl" runat="server"/>

<Utils:w id="My_w" runat="server"/>

</body>

</html>

Here''s the code behind for this page:

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

My_topdcl.topdcl1()

My_w.w1()

*End Sub

*I would really appreciate any help.

At this point, my only working solution seems to be to combine all the code
into 1 usercontrol, instead of having several. *Then variables can referto
variables in their own class with no problem.

In classic asp, I used includes with all the ''dim'' statements in the first,
and the subroutines in later includes.

Thanks.

Scott Baxter.



亲爱的Scott


忘记经典的asp


ASP.NET是一个完全不同的平台。它不仅仅是ASP的扩展,而且几乎没有从中继承。 VB.NET是
与ASP中使用的VB不同。


如果你想要可重用的代码或非整数的全局变量

到任何可视化控件然后在单独的.vb代码文件中创建它们

并将其存储在网站的APP_CODE文件夹中。在那里创建的任何名称空间或

类都将在所有页面的范围内,而不需要包含指令的




用户控件用于可重复使用的可视化控件和布局。它们不是用作代码的应用程序范围存储库。

公共范围内包含的任何内容都可以访问

only从包含它的实例的主机页面。例如,如果

页面上放置了topdcl的实例(可以有多个

,你可以选择它们),它将有一个唯一的标识符,例如: topdcl1名为addressesstring的

属性然后变成topdcl1.addressstring。

它不会从

中的任何其他用户控件访问相同或不同的页面,而且该值只是相关的

到topdcl的特定实例。


HTH

Dear Scott

Forget classic asp

ASP.NET is an entirely different platform. It is not merely an
extension of ASP and inherits practically nothing from it. VB.NET is
not the same as the VB used in ASP.

If you want re-usable code or global variables that are not integral
to any visual controls then create them in a separate .vb code file
and store it in the APP_CODE folder of the web site. Any namespaces or
classes created there will be within scope of all pages without the
need for include directives.

User controls are for re-usable visual controls and layouts. They are
not designed to act as an application-wide repository for code.
Anything contained within them that is publicly scoped is accessible
only from a host page that contains an instance of it. For example if
a page has an instance of topdcl placed on it (there can be as many of
them as you like) it will have a unique identifier e.g. topdcl1 The
property named "addressesstring" then becomes topdcl1.addressstring.
It will not be accessible from any other user control either within
the same or a different page, furthermore the value is only relevent
to that particular instance of topdcl.

HTH


这篇关于有没有办法在其他用户控件中引用公共属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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