在VB类文件中使用页面对象 [英] Using Page Object in VB Class File

查看:77
本文介绍了在VB类文件中使用页面对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目包含多个aspx页面。其中许多页面都有使用多个辅助函数的代码隐藏。


而不是将每个辅助函数复制到每个aspx页面中,我是

考虑使用VB类文件存储这些文件。


问题 -


- 我如何包括每个aspx页面中的这个类?


- 我如何调用这些函数?


- 我的一个函数是Page。的FindControl" ;.如何在类文件中访问Page

对象?当我在VB类文件中使用Page.FindControl时,VS .NET显示错误=引用非共享

成员需要一个对象引用。我已经在

类文件中导入了system.web。


Thx。


Bijoy


***通过Devdex发送 http://www.devdex。 com ***

不要只是参加USENET ......获得奖励!

My project contains multiple aspx pages. Many of these pages have
code-behind that use several helper functions.

Instead of copying each helper function into each aspx page, I am
thinking of using a VB Class file to store these.

Questions -

- How would I "include" this class in each aspx page?

- How would I call the functions?

- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file? When I use Page.FindControl in
my VB class file, VS .NET displays an error = "Reference to a non-shared
member requires an object reference". I''ve imported system.web in the
class file.

Thx.

Bijoy

*** Sent via Devdex http://www.devdex.com ***
Don''t just participate in USENET...get rewarded for it!

推荐答案

Bijoy,
Bijoy,
- 我将如何包括每个aspx页面中的这个类?
只需在项目中创建一个模块即可。它将在汇编中,并且自动包含&b; b。 (可访问)从您的所有页面。

- 我如何调用这些函数?
MyModule.MyFunction(arg1,arg2)

- 我的一个函数执行Page.FindControl。如何在类文件中访问Page
对象
函数MyFunction(pg as Page)As String

Dim ctrl as Control = pg.FindControl(" Blah" )

如果ctrl Is Nothing则返回Where Is It其他返回找到它

结束子


希望有所帮助!

-

Alex Papadimoulis
http://weblogs.asp.net/Alex_Papadimoulis

" Bijoy Naick" < b _ ***** @ donoteamil.yahoo.ca>在消息中写道

news:ON ************** @ tk2msftngp13.phx.gbl ...我的项目包含多个aspx页面。这些页面中的许多都有使用多个辅助函数的代码隐藏。

我没有将每个辅助函数复制到每个aspx页面中,而是考虑使用VB类文件存储这些。

问题 -

- 我如何包括每个aspx页面中的这个类?

- 我如何调用这些函数?

- 我的一个函数是Page.FindControl。如何在类文件中访问Page
对象?当我在我的VB类文件中使用Page.FindControl时,VS .NET显示错误=引用非共享
成员需要对象引用。我已经在
类文件中导入了system.web。

Thx。

Bijoy

***通过Devdex发送 http://www.devdex.com ***
不要只是参加USENET ......获得奖励!
- How would I "include" this class in each aspx page? Just create a module in your project. It will be in the assembly, and
automatically "included" (accessible) from all your pages.
- How would I call the functions? MyModule.MyFunction( arg1, arg2 )
- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file Function MyFunction( pg as Page ) As String
Dim ctrl as Control = pg.FindControl("Blah")
If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It"
End Sub

hope that helps!
--
Alex Papadimoulis
http://weblogs.asp.net/Alex_Papadimoulis
"Bijoy Naick" <b_*****@donoteamil.yahoo.ca> wrote in message
news:ON**************@tk2msftngp13.phx.gbl... My project contains multiple aspx pages. Many of these pages have
code-behind that use several helper functions.

Instead of copying each helper function into each aspx page, I am
thinking of using a VB Class file to store these.

Questions -

- How would I "include" this class in each aspx page?

- How would I call the functions?

- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file? When I use Page.FindControl in
my VB class file, VS .NET displays an error = "Reference to a non-shared
member requires an object reference". I''ve imported system.web in the
class file.

Thx.

Bijoy

*** Sent via Devdex http://www.devdex.com ***
Don''t just participate in USENET...get rewarded for it!



" Alex Papadimoulis" <人********** @ pa3.14padimoulis.com>在消息中写道

新闻:%2 ***************** @ TK2MSFTNGP10.phx.gbl ...
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
Bijoy ,
Bijoy,
- 我将如何包括每个aspx页面中的这个类?
- How would I "include" this class in each aspx page?


只需在项目中创建一个模块。它将在集合中,并自动包含。 (可访问)从你的所有页面。


Just create a module in your project. It will be in the assembly, and
automatically "included" (accessible) from all your pages.




我个人建议对模块,这是一个OO前功能。相反,

继续创建一个具有公共共享子和/或函数的公共类。



I personally recommend against modules, which are a pre-OO feature. Instead,
go ahead and create a Public class with Public Shared subs and/or Functions.

- 我将如何调用函数?
- How would I call the functions?


MyModule.MyFunction(arg1,arg2)


MyModule.MyFunction( arg1, arg2 )




MyClass.MyFunction(arg1,arg2)



MyClass.MyFunction(arg1, arg2)

- 我的一个函数执行Page.FindControl。如何在类文件中访问Page
对象
- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file


函数MyFunction(pg as Page)As String
Dim ctrl as Control = pg.FindControl(" Blah" )
如果ctrl Is Nothing那么返回它在哪里其他返回找到它
End Sub


Function MyFunction( pg as Page ) As String
Dim ctrl as Control = pg.FindControl("Blah")
If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It"
End Sub




相当不错,但如果你签名是:


函数MyFunction(作为控件的ctl)


然后你就可以处理你不想搜索整个的情况

页面。

-

John Saunders

johnwsaundersiii at hotmail



Pretty good, but if you make the signature be:

Function MyFunction(ctl as Control)

then you''ll be able to handle cases where you don''t want to search the whole
page.
--
John Saunders
johnwsaundersiii at hotmail


你可以创建继承自web.page并在此处编写所有函数的PageBase类。

在aspx页面中,codebehind类继承了这个Pageclass ..

就像这样

你的PageBAse类:继承web.page

写下所有你的函数

end class


你的aspx.vb类后面的代码

公共类urpagename:PageBase

u可以使用base.function名称引用...

end class


" Bijoy Naick"写道:
You can create PageBase class which inherits from web.page and write all functions here..
In aspx page codebehind class inherit this Pageclass..
It is like this
Your PageBAse class:inherits web.page
write all ur functions
end class

ur aspx.vb code behind class
public class urpagename:PageBase
u can refer using base.function name...
end class

"Bijoy Naick" wrote:
我的项目包含多个aspx页面。这些页面中的许多都有使用多个辅助函数的代码隐藏。

我没有将每个辅助函数复制到每个aspx页面中,而是考虑使用VB类文件存储这些。

问题 -

- 我如何包括每个aspx页面中的这个类?

- 我如何调用这些函数?

- 我的一个函数是Page.FindControl。如何在类文件中访问Page
对象?当我在我的VB类文件中使用Page.FindControl时,VS .NET显示错误=引用非共享
成员需要对象引用。我已经在
类文件中导入了system.web。

Thx。

Bijoy

***通过Devdex发送 http://www.devdex.com ***
不要只是参加USENET ......获得奖励!
My project contains multiple aspx pages. Many of these pages have
code-behind that use several helper functions.

Instead of copying each helper function into each aspx page, I am
thinking of using a VB Class file to store these.

Questions -

- How would I "include" this class in each aspx page?

- How would I call the functions?

- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file? When I use Page.FindControl in
my VB class file, VS .NET displays an error = "Reference to a non-shared
member requires an object reference". I''ve imported system.web in the
class file.

Thx.

Bijoy

*** Sent via Devdex http://www.devdex.com ***
Don''t just participate in USENET...get rewarded for it!



这篇关于在VB类文件中使用页面对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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