全球财产 [英] Global property

查看:71
本文介绍了全球财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主aspx页面包含许多用户控件。

如何创建一个可在每个用户中看到的全局属性

控件?


谢谢

I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks

推荐答案

创建公共财产


说出你的页面是WebForm1类型

公共类WebForm1

继承System.Web.UI.Page

private _myvalue as string =" SomeValue"

public readonly property MyValue()as string

get

return _myvalue

end get

结束财产


子页面加载...

....

End Sub


....

结束课


在您的用户控件中,您可以通过以下方式访问MyValue:


dim pageValue as string = ctype(Page,WebForm1).MyValue

每个用户控件都可以访问Page,并将其转换为特定的

类型,您可以访问它的公共专业人士perty /方法..


Karl

" Mark Goldin" <毫安******** @ comcast.net>在消息中写道

新闻:eH **************** @ TK2MSFTNGP12.phx.gbl ...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
....
End Sub

....
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the specific
type, you have access to it''s public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
我有主要内容带有多个用户控件的aspx页面。
如何创建一个可在每个用户控件中看到的全局属性?

谢谢
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks



Karl,


这很有意思。但是对我来说似乎并不合适。一个

用户控件可以放在任何页面上。如果您尝试

并将页面对象转换为托管,则不会导致此问题。在一个特定的班级?


问题可能不是正确的词。难道你不应该做某种测试吗

在投票前确保页面的类型正确吗?


如果TypeOf(页面)是WebForm1那么

dim pageValue as string = ctype(Page,WebForm1).MyValue

结束如果


格雷格


" Karl" < karl REMOVE @ REMOVE openmymind REMOVEMETOO。 ANDME net>写在

消息新闻:ew **************** @ TK2MSFTNGP14.phx.gbl ...
Karl,

This is quite interesting. But something doesn''t seem right to me. A
usercontrol can be placed on any page. Won''t this cause problems if you try
and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn''t you do some sort of test to
be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew****************@TK2MSFTNGP14.phx.gbl...
创建公众属性

说你的页面是WebForm1类型

公共类WebForm1
继承System.Web.UI.Page

private _myvalue as string =" SomeValue"
public readonly属性MyValue()as string
get
return _myvalue
end get
end property

Sub页面加载......
...
End Sub

...
结束课

在您的用户控件中,您可以通过以下方式访问MyValue:

dim pageValue as string = ctype(Page,WebForm1).MyValue

每个用户控件都可以访问Page,并将其转换为
特定类型,您可以访问它的公共财产/方法..

Karl

" Mark Goldin" <毫安******** @ comcast.net>在消息中写道
新闻:eH **************** @ TK2MSFTNGP12.phx.gbl ...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the specific type, you have access to it''s public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
我有一个主要的aspx页面用户控件的数量。
如何创建一个在每个用户
控件中都可见的全局属性?

谢谢
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks




是的,

您的问题陈述没有提及。


如果您需要从多个页面进行此操作,最好的解决方案是使它们实现一个界面并将页面转换为所述界面...如果这是什么

你需要,知道。


Karl


" Greg Burns" < greg_burns@DONT_SPAM_ME_hotmail.com>在消息中写道

新闻:uD ************** @ TK2MSFTNGP14.phx.gbl ...
Yes,
Your problem statement didn''t mention that.

If you need this from multiple page, the best solution is to make them
implement an interface and cast the page to said interface...if this is what
you need, lemme know.

Karl

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
Karl,
这很有意思。但是对我来说似乎并不合适。
用户控件可以放在任何页面上。如果您尝试将Page对象强制转换为托管对象,那么这不会导致问题吗?在一个特定的班级?

问题可能不是正确的词。难道你不应该做某种测试吗?确保页面在转换之前是正确的类型吗?

如果TypeOf(页面)是WebForm1那么
dim pageValue as string = ctype(Page,WebForm1).MyValue
结束如果

Greg

" Karl" < karl REMOVE @ REMOVE openmymind REMOVEMETOO。 ANDME net>在消息新闻中写道:ew **************** @ TK2MSFTNGP14.phx.gbl ...
Karl,

This is quite interesting. But something doesn''t seem right to me. A
usercontrol can be placed on any page. Won''t this cause problems if you try and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn''t you do some sort of test to
be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew****************@TK2MSFTNGP14.phx.gbl...
创建公共财产
说你的页面是WebForm1类型

公共类WebForm1
继承System.Web.UI.Page

private _myvalue as string =" SomeValue"
公共只读属性MyValue()为字符串
获取
返回_myvalue
结束获取
结束属性

子页面加载.. 。
...
End Sub

...
结束课

在您的用户控件中,您可以通过以下方式访问MyValue:

dim pageValue as string = ctype(Page,WebForm1).MyValue

每个用户控件都可以访问Page,并将其转换为
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the


具体的

类型,您可以访问它的公共财产/方法..

Karl

" Mark Goldin" <毫安******** @ comcast.net>在消息中写道
新闻:eH **************** @ TK2MSFTNGP12.phx.gbl ...
type, you have access to it''s public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
我有一个主要的aspx页面用户控件的数量。
如何创建一个在每个用户
控件中都可见的全局属性?

谢谢
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks





这篇关于全球财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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