在多个项目页面上重用代码 [英] Reuse code on multiple pages of project

查看:59
本文介绍了在多个项目页面上重用代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 -


我使用的是Visual Studio .Net。我需要一个如何构建一个

类的例子,它可以在整个项目中使用,我可以在项目的各个页面中包含它的subs和

函数。 />

我用谷歌搜索了这个,要么我没有使用正确的单词,要么就没有b $ b似乎很多。


任何帮助将不胜感激!

-

桑迪

Hello -

I am using Visual Studio .Net. I need an example of how to construct a
class that can be used throughout a project where I can include its subs and
functions in various pages in the project.

I googled this and either I didn''t use the correct words, or there doesn''t
seem to be much on it.

Any help will be appreciated!
--
Sandy

推荐答案



一分钟前我自己引用了那个页面:)

http://aspnet.4guysfromrolla.com/articles/041305-1.aspx


告诉我如果您还有其他问题..


干杯,

Tom Pester

Just referenced that page myself a minute ago :)

http://aspnet.4guysfromrolla.com/articles/041305-1.aspx

Let me know if you have any more questions..

Cheers,
Tom Pester
你好 -

我正在使用Visual Studio .Net。我需要一个如何构建一个类的例子,这个类可以在整个项目中使用,我可以在项目的各个页面中包含它的
子和函数。

我用google搜索这个,或者我没有使用正确的词语,或者那里似乎没有太多的东西。

任何帮助将不胜感激!
-
Sandy
Hello -

I am using Visual Studio .Net. I need an example of how to construct
a class that can be used throughout a project where I can include its
subs and functions in various pages in the project.

I googled this and either I didn''t use the correct words, or there
doesn''t seem to be much on it.

Any help will be appreciated!
--
Sandy



http://www.c-sharpcorner.com/2/pr12.asp


" Sandy" <萨*** @ discussions.microsoft.com>在消息中写道

新闻:5A ********************************** @ microsof t.com ...
http://www.c-sharpcorner.com/2/pr12.asp

"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
你好 -

我正在使用Visual Studio .Net。我需要一个如何构建一个可以在整个项目中使用的类的示例,我可以在项目的各个页面中包含它的子函数和
函数。

任何帮助都将受到赞赏!
-
Sandy
Hello -

I am using Visual Studio .Net. I need an example of how to construct a
class that can be used throughout a project where I can include its subs
and
functions in various pages in the project.

I googled this and either I didn''t use the correct words, or there doesn''t
seem to be much on it.

Any help will be appreciated!
--
Sandy



感谢您的回复!


我正在使用vb。净。如果可能的话,我不想去dll路线。


我确实看到了Scott Mitchell的文章,但是它的内容就像泥巴一样清晰。我。


无论如何,我有以下代码,并在RegisterStartupScript上得到一条蓝色波浪线

,信息为:

"不能在共享方法中引用类的实例成员

或没有类的显式实例的共享成员初始化程序。


HERE''S MY CLASS:


Imports System.Web.UI.WebControls

Imports System.Web.UI

Imports System.Web.UI.Page


命名空间GenRFE


公共类RFELIB

继承System.Web .UI.Page


Dim ctrl as WebControl


Public Shared Sub SetFocus(ByVal ctrl as Control)

''专注于控制

Dim sb as New System.Text.StringBuilder

sb.Append("< scri pt language =''javascript''>")

sb.Append(" document.getElementById(''")

sb.Append(ctrl。 ClientID)

sb.Append("'')。focus();")

sb.Append("< / script>")

RegisterStartupScript(" SetFocus",sb.ToString)

结束子

结束班


结束命名空间


在我的页面中使用SETFOCUS常规:


进口RidingForEveryone.GenRFE

进口RidingForEveryone.GenRFE。 RFELIB


公共类联系人

继承System.Web.UI.Page


私有子Page_Load(ByVal发送者) As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load


SetFocus(txtContactUs)

End Sub


我做错了什么?

-

Sandy

Thanks for your responses!

I am using vb .net. I didn''t want to go the dll route, if at all possible.

I did see Scott Mitchell''s article, but it''s about as clear as mud to me.

At any rate, I have the following code and am getting a a blue squiggly line
on RegisterStartupScript with the message:
"Cannot refer to an instance member of a class from within a shared method
or shared member initializer without an explicit instance of the class."

HERE''S MY CLASS:

Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports System.Web.UI.Page

Namespace GenRFE

Public Class RFELIB
Inherits System.Web.UI.Page

Dim ctrl as WebControl

Public Shared Sub SetFocus(ByVal ctrl as Control)
''Sets focus on control
Dim sb as New System.Text.StringBuilder
sb.Append("<script language=''javascript''>")
sb.Append("document.getElementById(''")
sb.Append(ctrl.ClientID)
sb.Append("'').focus();")
sb.Append("</script>")
RegisterStartupScript("SetFocus", sb.ToString)
End Sub
End Class

End Namespace

USING SETFOCUS ROUTINE IN MY PAGE:

Imports RidingForEveryone.GenRFE
Imports RidingForEveryone.GenRFE.RFELIB

Public Class ContactUs
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

SetFocus(txtContactUs)
End Sub

What am I doing wrong?
--
Sandy


这篇关于在多个项目页面上重用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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