Delcare一个公共变量。 [英] Delcare a Public Variable.

查看:72
本文介绍了Delcare一个公共变量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.NET中的新手学习2.


我正在创建一个简单的ASP.NET 2页面并从链接中提取查询字符串

我想在页面上一遍又一遍地使用这个查询字符串。


示例。


公共变量

Dim myVar as string = Request.querystring(" MyVar")

结束公共变量


然后我可以从任何地方调用此变量抓住MyVar。


谢谢!

Phil

Newbie learning in VB.NET 2.

I''m creating a simple ASP.NET 2 page and I pulling a querystring from a link
and I want to use this querystring over and over again through out the page.

Example.

Public Variable
Dim myVar as string = Request.querystring("MyVar")
End Public Variable

Then I can just call this variable from anywhere to grab MyVar.

Thanks!
Phil

推荐答案

刚才放:


在你的页面类中将myVar变暗为字符串


但不在任何特定的子或函数内,然后

把:


myVar = Request.querystring(" MyVar")

你的Page_Load子中的
,它将可用于所有其他潜艇&安培;功能

整个页面。


" Phillip Vong" < phillip_vong * at * yahoo * dot * comwrote in message

news:%2 **************** @ TK2MSFTNGP05.phx.gbl ...
Just put:

Dim myVar as string

in your page class but not inside any particular sub or function and then
put:

myVar = Request.querystring("MyVar")

in your Page_Load sub and it will be available to all other subs & functions
throughout the page.


"Phillip Vong" <phillip_vong*at*yahoo*dot*comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

在VB.NET中学习新手2.


我正在创建一个简单的ASP.NET 2页面和我从

链接中提取查询字符串,我想一遍又一遍地使用此查询字符串

页面。


示例。


公共变量

将myVar调暗为string = Request.querystring(" MyVar")

结束公共变量


然后我可以从任何地方调用这个变量来获取MyVar。


谢谢!

Phil
Newbie learning in VB.NET 2.

I''m creating a simple ASP.NET 2 page and I pulling a querystring from a
link and I want to use this querystring over and over again through out
the page.

Example.

Public Variable
Dim myVar as string = Request.querystring("MyVar")
End Public Variable

Then I can just call this variable from anywhere to grab MyVar.

Thanks!
Phil



在Page_Load方法上方声明字符串变量(不在方法体内。

方法。这就是''范围到类级别。

然后,在Page_Load方法中或在其内部分配值。

Peter

-

网站: http://www.eggheadcafe.com

UnBlog: http://petesbloggerama.blogspot.com

短网址&更多: http://ittyurl.net


Phillip Vong写道:
Declare the string variable above the Page_Load method (not inside the body
of the method. This puts it''s scope to class level.
Then, assign the value either there or inside the Page_Load method.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Phillip Vong" wrote:

在VB.NET中学习新手2.


我正在创建一个简单的ASP.NET 2页面我从一个链接中拉出一个查询字符串

我希望在页面中一遍又一遍地使用这个查询字符串。


示例。


公共变量

将myVar调暗为string = Request.querystring(" MyVar")

结束公共变量

然后我可以从任何地方调用这个变量来获取MyVar。


谢谢!

Phil
Newbie learning in VB.NET 2.

I''m creating a simple ASP.NET 2 page and I pulling a querystring from a link
and I want to use this querystring over and over again through out the page.

Example.

Public Variable
Dim myVar as string = Request.querystring("MyVar")
End Public Variable

Then I can just call this variable from anywhere to grab MyVar.

Thanks!
Phil


或者创建一个具有惰性初始化的属性:


私有_myVar作为字符串

受保护的ReadOnly属性MyVar()As String

获取

如果_myVar什么都没有那么

_myVar = Request.QueryString(" MyVar")

如果_myVar什么都没有

_myVar = String.Empty

结束如果

结束如果

返回_myVar

结束获取

结束财产


我看起来可能很糟糕,但实际上这很简单。然后在

页面代码的任何地方都可以使用该属性:


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

ByVal e As System.EventArgs)处理Me.Load


如果不是IsPostBack然后

DisplaySomeInformationBasedOnMyVarValue(MyVar)

结束如果


end sub


-

Milosz

" Peter Bromberg [C#MVP ]"写道:
Or create a property with lazy intialization:

Private _myVar As String
Protected ReadOnly Property MyVar() As String
Get
If _myVar Is Nothing Then
_myVar = Request.QueryString("MyVar")
If _myVar Is Nothing Then
_myVar = String.Empty
End If
End If
Return _myVar
End Get
End Property

I may look horrible, but it''s actually simple idea. Then wherever on the
page code you can use the property:

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

If Not IsPostBack Then
DisplaySomeInformationBasedOnMyVarValue(MyVar)
End If

end sub

--
Milosz
"Peter Bromberg [C# MVP]" wrote:

在Page_Load方法上面声明字符串变量(不在体内。

方法。这就是它的范围到班级。

然后,在Page_Load方法的内部或内部分配值。

Peter

-

网站: http://www.eggheadcafe.com

UnBlog: http://petesbloggerama.blogspot.com

简短网址及其他内容: http://ittyurl.net



" Phillip Vong"写道:
Declare the string variable above the Page_Load method (not inside the body
of the method. This puts it''s scope to class level.
Then, assign the value either there or inside the Page_Load method.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Phillip Vong" wrote:

在VB.NET中学习新手2.


我正在创建一个简单的ASP.NET 2页面,我从一个链接中拉出一个查询字符串

我想一遍又一遍地使用这个查询字符串他的页面。


示例。


公共变量

将myVar调暗为string = Request.querystring(" MyVar")

结束公共变量


然后我可以从任何地方调用此变量来获取MyVar。


谢谢!

Phil

Newbie learning in VB.NET 2.

I''m creating a simple ASP.NET 2 page and I pulling a querystring from a link
and I want to use this querystring over and over again through out the page.

Example.

Public Variable
Dim myVar as string = Request.querystring("MyVar")
End Public Variable

Then I can just call this variable from anywhere to grab MyVar.

Thanks!
Phil


这篇关于Delcare一个公共变量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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