从类代码(vb.net)读取/写入aspx页面上的控件 [英] Read/Write controls on aspx page from class code (vb.net)

查看:94
本文介绍了从类代码(vb.net)读取/写入aspx页面上的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑这很容易,但我已经被困了一天试图解决这个问题..


我希望能够拥有无限数量的aspx页面在一个类文件中使用代码。我希望该类文件中的代码能够读取和写入aspx页面上的控件。例如,在所有aspx页面上,我将有一个名为label1的标签。从类文件中的代码,我希望能够做一些像label1.text =" hello world


我知道httpcontext,现在可以做_context.response.write (hello world),但我想要一个适用于标签和其他标准服务器控件的通用解决方案,并且是通用的,这样我以后可以添加更多的aspx页面而不必更改提供代码的类文件


请尽可能提供一个完整的示例,说明我需要在aspx页面中添加什么以及我需要在类文件中添加什么。在UseNet上有很多关于这个主题的帖子,但没有一个假设我有限的背景知识


谢谢


ps - 我是发布这两次...第二次用我的MSDN订阅者电子邮件,得到承诺的48小时回复...对不起,我之前没有分配我的电子邮件。

I suspect this is easy, but I have been stumped for a day trying to solve this..

I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code in that class file to be able to read and write the controls on the aspx pages. For example, on all the aspx pages, I''ll have a label named label1. From code in the class file, I want to be able to do something like label1.text = "hello world

I know about httpcontext, and can now do _context.response.write("hello world"), but I want a general solution that works with labels and other standard server controls, and is generic so that I can add more aspx pages later without having to change the class file that provides the code

Please give a complete example if possible, showing what I need to put in the aspx pages and what I need to put in the class file. There are dozens of posts about this subject on UseNet, but none that assume my limited background knowledge

Thanks

ps - i''m posting this twice... the second time with my MSDN subscriber email, to get a promised 48 hour response... sorry, I didn''t have my email assigned earlier.

推荐答案




我不知道任何C#。你在vb.net中有一个例子


你是说类文件中的代码需要预先知道可能调用它的所有aspx页面的名称吗?这不是理想的,但不是一个大问题。但是,让100个aspx页面使用相同的类代码是否可以?我不得不说,我的感觉是有一些方法来制作通用解决方案,所以我可以拥有一百万个未知的aspx页面都使用相同的类代码。我真的非常喜欢通用解决方案。请记住,这些aspx页面上将有相同的服务器控件,每个控件的名称相同


谢谢


---- - Steven Cheng [MSFT]写道:----





根据你的描述,你想要操作某个aspx页面的控件
组件类中的
成员。它需要与很多页面相遇,是的


至于这个问题,这里有一些我的建议

1.如果你想要检索当前处理的页面的实例

asp.net页面。您可以在组件中使用以下代码


public static void ComponentMethod(

SimplePage sp =(SimplePage)HttpContext.Current.Handler

sp.Text1 =" Text Value1"

sp.Text2 =" Text Value2"

sp.Text3 =" Text Value3"

#Simple Page是某个aspx页面的Codebehind类。


如果你想要检索页面的某个Control成员,你需要

将其范围声明更改为public,因为默认控制成员

被定义为受保护。例如


protected System.Web.UI.WebControls.TextBox TextBox1

#将protected更改为public


或者你可以定义一个公共pageclass的属性包装

控制成员,例如

公共字符串文本


ge


返回TextBox1.Text


se />

TextBox1.Text = value


因此,您可以在某个组件中对其进行检索并对其进行修改,因为我

如上所述。


另外,我上面提到的方法是基于我们知道有多少

页面类并编写组件'根据页面

类的代码,您需要在

页面类中定义公共属性。如果有许多不同的页面类和组件

想要在这些页面类上没有信息,我担心这种方式不起作用。

你这么认为吗?问候


Steven Chen

微软在线支持


安全! www.microsoft.com/securit

(此帖子按原样提供,不作任何保证,并且不授予

权利。


在ASP.NET上获取预览
http://msdn.microsoft.com/asp.net/whidbey/ default.asp



Hi

I don''t know any C#. Do you have an example in vb.net

Are you saying that the code in the class file needs to know up front the names of all the aspx pages that may call it? This is not ideal, but not a huge problem. But would it be OK to have 100 aspx pages use the same class code? I have to say, my feeling is that there is some way to make a generic solution, so I can have a million unknown aspx pages all use the same class code. I really, really prefer a generic solution. Remember, these aspx pages will have the same server controls on them, with the same names for each control

Thanks

----- Steven Cheng[MSFT] wrote: ----

Hi

From your description, you''d like to operate a certain aspx page''s control
member in a component class. And it need to meet with many pages,yes

As for this problem, here is some of my suggestions
1. If you''d like to retrieve the Page''s instance of the current processed
asp.net page. You may use the following code in the component

public static void ComponentMethod(

SimplePage sp = (SimplePage)HttpContext.Current.Handler
sp.Text1 = "Text Value1"
sp.Text2 = "Text Value2"
sp.Text3 = "Text Value3"
#Simple Page is the Codebehind class of the certain aspx page.

If you want to retrieve the page''s certain Control member, you need to
change its scope declaration to "public" because by default control member
is defined a s "protected". For example

protected System.Web.UI.WebControls.TextBox TextBox1
#change the "protected" to "public

or you can define a public property for the pageclass to wrapper the
control member, such as
public string Text

ge

return TextBox1.Text

se

TextBox1.Text = value

So that you can retrive it and modify it in the certain component as I
mentioned above.

In addition, the means I mentioned above is based on that we know how many
pageclasses we have and write the component''s code according to the page
class and you need to define the public properties in the
page classes. If there are many different pageclasses and the component
want to have no infos on those page classes, I''m afraid this way not work.
Do you think so
Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Get Preview at ASP.NET whidbe
http://msdn.microsoft.com/asp.net/whidbey/default.asp








感谢您的跟进。不仅仅是前面的名字,而是页面的'

代码隐藏类。我们需要根据它的
$ b $操作一个类的实例b类,是吗?另外,可以让很多页面共享一个页面类,但

这会导致很多问题,因为我们不能完全制作这么多页面

具有相同的功能。一个想法是拥有一个母版页(所有页面的公共页面类

),以便所有页面类派生自基页

类包含需要在常见的

组件中操作的常用功能。你是这么认为的吗?


另外,下面是某个网站,可以帮助将C#代码翻译成

VB.NET。我相信它会对你有所帮助。
http ://authors.aspalliance.com/aldot...translate.aspx


谢谢。

问候,


Steven Cheng

Microsoft在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx

Hi,

Thanks for the followup. Not simply the front the names but the page''s
codebehind class. We need to operate a class''s instance according to its
class, yes? Also, its ok to have many pages share one page class, but
that''ll cause many problem since we can''t make so many pages completely
have same features. One ideas is to have a master page(a common page class
for all the pages) so that all the page class derived from the base page
class which contains the common features need to be operated in the common
component. Do you think so?

In addtion, below is certain website which can help translate C# code into
VB.NET. I believe it''ll be helpful to you.
http://authors.aspalliance.com/aldot...translate.aspx

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


您好,


根据您的描述,您会喜欢在组件类中操作某个aspx页面的控件

成员。它需要与很多页面相遇,是吗?


至于这个问题,这里有一些我的建议:

1.如果你想要检索当前处理的页面的实例

asp.net页面。您可以在组件中使用以下代码:


public static void ComponentMethod()

{

SimplePage sp =(SimplePage )HttpContext.Current.Handler;

sp.Text1 =" Text Value1";

sp.Text2 =" Text Value2";

sp.Text3 =" Text Value3";

}


#Simple Page是某个aspx页面的Codebehind类。


如果你想检索页面的某个控制成员,你需要

将其范围声明改为public因为默认情况下控制成员

被定义为sprotected。例如:


protected System.Web.UI.WebControls.TextBox TextBox1;

#changeprotected到公共


或者您可以为页面类定义一个公共属性来包装

控制成员,例如

公共字符串Text1

{

get

{

返回TextBox1.Text;

}

套装

{

TextBox1.Text = value;

}

}


这样你就可以在某个组件中对它进行检索和修改,就像我上面提到的
一样。


另外,我上面提到的方法是基于我们知道我们有多少

页面类,并根据页面编写组件的代码

您需要在

页面类中定义公共属性。如果有许多不同的页面类和组件

想要在这些页面类上没有信息,我恐怕这种方式不起作用。

你这么认为吗?

问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx


Hi,

From your description, you''d like to operate a certain aspx page''s control
member in a component class. And it need to meet with many pages,yes ?

As for this problem, here is some of my suggestions:
1. If you''d like to retrieve the Page''s instance of the current processed
asp.net page. You may use the following code in the component:

public static void ComponentMethod()
{
SimplePage sp = (SimplePage)HttpContext.Current.Handler;
sp.Text1 = "Text Value1";
sp.Text2 = "Text Value2";
sp.Text3 = "Text Value3";
}

#Simple Page is the Codebehind class of the certain aspx page.

If you want to retrieve the page''s certain Control member, you need to
change its scope declaration to "public" because by default control member
is defined a s "protected". For example:

protected System.Web.UI.WebControls.TextBox TextBox1;
#change the "protected" to "public"

or you can define a public property for the pageclass to wrapper the
control member, such as
public string Text1
{
get
{
return TextBox1.Text;
}
set
{
TextBox1.Text = value;
}
}

So that you can retrive it and modify it in the certain component as I
mentioned above.

In addition, the means I mentioned above is based on that we know how many
pageclasses we have and write the component''s code according to the page
class and you need to define the public properties in the
page classes. If there are many different pageclasses and the component
want to have no infos on those page classes, I''m afraid this way not work.
Do you think so?
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx




这篇关于从类代码(vb.net)读取/写入aspx页面上的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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