且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从用户控件引用主页面上的var

更新时间:2023-12-03 08:41:04

Michael,


使用私有变量和公共财产。


私有_UserId为Int32

公共财产UserId()如Int32

获取

返回_UserId

结束获取

设置(ByVal值为Int32)

_UserId =价值

结束集

结束财产


''---现在这里就是诀窍:

''在任何页面上你想访问该物业

''来自HTML视图下面的

''< @pagedelcaration put:

''<%@ MasterType VirtualPath ="〜/ MasterPage.master" %GT;像这样:

<%@ Page Language =" VB" MasterPageFile ="〜/ MasterPage.master"

MaintainScrollPositionOnPostback =" true" AutoEventWireup =" false"

CodeFile =" Auction.aspx.vb"继承= QUOT;拍卖&QUOT;标题= QUOT;拍卖&QUOT; %>


<%@ MasterType VirtualPath ="〜/ MasterPage.master" %>


指向主文件的MasterType声明是什么

让你访问主人的属性和其他公共声明
页。


问候,


-

S. Justin Gengo

Web开发人员/程序员


免费代码库:
http://www.aboutfortunate.com


混乱无序。

Nietzsche

" Michael" &LT;弥***** @ discussions.microsoft.com&GT;在消息中写道

news:71 ********************************** @ microsof t.com ...
Michael,

Do it with a private variable and public property.

Private _UserId As Int32

Public Property UserId() As Int32
Get
Return _UserId
End Get
Set (ByVal value As Int32)
_UserId = Value
End Set
End Property

''---And now here''s the trick:
'' On any page you want to access the property
'' from in the HTML View just below the
'' <@pagedelcaration put:
'' <%@ MasterType VirtualPath="~/MasterPage.master" %> Like this:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
MaintainScrollPositionOnPostback="true" AutoEventWireup="false"
CodeFile="Auction.aspx.vb" Inherits="Auction" title="Auction" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>

The MasterType declaration pointing to the master file in question is what
let''s you access properties and other public declarations in the master
page.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
我在母版页代码隐藏文件中设置了一个公共变量。现在我想从UserControl中设置该值,但我似乎无法找到这样做的方法。有没有人有任何想法?我基本上试图将它设置为
以便我可以在主页面中保留用户信息(userid,ect),以便其他页面可以访问它。感谢您的任何想法。
Michael
I have setup a public variable in the Master Page "code-behind-file". Now I
would like to set that value from the UserControl, but I can''t seem to
find a
way to do this. Does anyone have any ideas? I''m basically trying to set it
up
so that I can keep the User infor (userid, ect) in the Masterpage so that
other pages can access it. Thanks for any ideas.
Michael



2006年3月31日星期五11:30:03 - 0600,Michael

< Mi ***** @ discussion.microsoft.com>写道:
On Fri, 31 Mar 2006 11:30:03 -0600, Michael
<Mi*****@discussions.microsoft.com> wrote:
我在主页面中设置了一个公共变量代码隐藏文件。
现在我想设置该值UserControl,但我似乎无法找到一种方法来做到这一点。有没有人有任何想法?我基本上试图设置
以便我可以在主页中保留用户infor(userid,ect),以便其他页面可以访问它。感谢您的任何想法。
Michael
I have setup a public variable in the Master Page "code-behind-file".
Now I
would like to set that value from the UserControl, but I can''t seem to
find a
way to do this. Does anyone have any ideas? I''m basically trying to set
it up
so that I can keep the User infor (userid, ect) in the Masterpage so that
other pages can access it. Thanks for any ideas.
Michael




UserControl有一个.Page属性,您可以从中获取其主页


ex:

this.Page.MasterPageFile


然后将其适当地转换为MasterPage类型以访问您的

属性。


-

Craig

Microsoft MVP - ASP / ASP.NET



The UserControl has a .Page property, from which you can get its MasterPage

ex:
this.Page.MasterPageFile

then cast that appropriately to the MasterPage type to access your
property.

--
Craig
Microsoft MVP - ASP/ASP.NET




感谢您的回复。我尝试设置一个公共财产,就像你建议的
一样,我仍然无法访问Master的UserControl上的Master Page中的Property $

页面。

Page.Master。????不工作

我也尝试在同一命名空间中包装Master Page,Usercontrol和

我有其他错误(在另一条消息中看到了这个建议)。我是否试图以错误的方式访问主人?
或者我错过了什么。谢谢。

Michael

" S. Justin Gengo写道:
Hi,
Thanks for the reply. I tried setting up a Public Property, just as you
suggested and I still can''t get access to the Property in the Master Page
from the UserControl on that Master Page.
Page.Master.???? don''t work
I''ve also tried wrapping Master Page, Usercontrol in the same namespace and
I got other errors (saw this suggestion in another message). Am I trying to
access the master in the wrong way? Or am I missing something. Thanks.
Michael
"S. Justin Gengo" wrote:
迈克尔,

使用私人变量和公共财产。

私人_UserId作为Int32

公共属性UserId()为Int32
返回_UserId
结束获取
设置(ByVal值为Int32)
_UserId = Value
结束集
结束财产

''---现在这里的诀窍:
''在任何你想访问该物业的页面上
' '来自HTML视图中的
''< @pagedelcaration put:
''<%@ MasterType VirtualPath ="〜/ MasterPage.master" %GT;像这样:
<%@ Page Language =" VB" MasterPageFile ="〜/ MasterPage.master"
MaintainScrollPositionOnPostback =" true" AutoEventWireup =" false"
CodeFile =" Auction.aspx.vb"继承= QUOT;拍卖&QUOT;标题= QUOT;拍卖&QUOT; %>

<%@ MasterType VirtualPath ="〜/ MasterPage.master" %>

指向主文件的MasterType声明是
让您在主页面中访问属性和其他公共声明。

问候,

- S. Justin Gengo
Web开发人员/程序员

免费代码库:
http://www.aboutfortunate.com

Out of of混乱来了。
Nietzsche

" Michael" &LT;弥***** @ discussions.microsoft.com&GT;在消息中写道
新闻:71 ********************************** @ microsof t.com。 ..
Michael,

Do it with a private variable and public property.

Private _UserId As Int32

Public Property UserId() As Int32
Get
Return _UserId
End Get
Set (ByVal value As Int32)
_UserId = Value
End Set
End Property

''---And now here''s the trick:
'' On any page you want to access the property
'' from in the HTML View just below the
'' <@pagedelcaration put:
'' <%@ MasterType VirtualPath="~/MasterPage.master" %> Like this:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
MaintainScrollPositionOnPostback="true" AutoEventWireup="false"
CodeFile="Auction.aspx.vb" Inherits="Auction" title="Auction" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>

The MasterType declaration pointing to the master file in question is what
let''s you access properties and other public declarations in the master
page.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:71**********************************@microsof t.com...
我在母版页代码隐藏文件中设置了一个公共变量。现在我想从UserControl中设置该值,但我似乎无法找到这样做的方法。有没有人有任何想法?我基本上试图将它设置为
以便我可以在主页面中保留用户信息(userid,ect),以便其他页面可以访问它。感谢您的任何想法。
Michael
I have setup a public variable in the Master Page "code-behind-file". Now I
would like to set that value from the UserControl, but I can''t seem to
find a
way to do this. Does anyone have any ideas? I''m basically trying to set it
up
so that I can keep the User infor (userid, ect) in the Masterpage so that
other pages can access it. Thanks for any ideas.
Michael