UserControl可以对托管页面代码隐藏执行某些操作吗? [英] Can a UserControl perform some action on the hosting page codebehind?

查看:87
本文介绍了UserControl可以对托管页面代码隐藏执行某些操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个带有几个文本框和几个按钮的UserControl

(保存和取消按钮) )。这个按钮的Click事件当然是在

UserControl的代码隐藏中,所以这是我的问题。


一旦UserControl被删除在容器页面上,我如何从用户控件的代码隐藏处对容器页面的代码隐藏执行某些操作?b $ b $ User例如,假设UserControl在容器页面上的Multiview控件的一个Views中被删除了

。通过

点击取消按钮UserControl的按钮,我想更改容器页面的Multiview控件的

活动视图。


如何在ASP中完成.NET 2.0?


提前致谢,


-Benton

Hi there,

I have a UserControl with a couple of textboxes and a couple of buttons
("Save" and "Cancel"). The Click event for this buttons is in the
UserControl''s codebehind of course, so here''s my question.

Once the UserControl is dropped onto the container page, how can I perform
some action on the codebehind of the container page from the codebehind of
the UserControl? For instance, suppose that the UserControl is dropped
inside one of the Views of a Multiview control on the container page. By
clicking the "Cancel" button of the UserControl, I would like to change the
active view of the container page''s Multiview control.

How can this be done in ASP.NET 2.0?

Thanks in advance,

-Benton

推荐答案

我建​​议使用UserControl中的自定义事件(例如

已取消)并在页面中订阅它。然后它将由

页面来处理事件(切换活动视图)。

Benton写道:
I would suggest using a custom event from the UserControl (eg
Cancelled) and subscribing to it in the Page. It will then be up to the
page to handle the event (switch active views).
Benton wrote:

你好,

我有一个带有几个文本框和几个按钮的UserControl

(保存和取消按钮)。这个按钮的Click事件当然是在

UserControl的代码隐藏中,所以这是我的问题。


一旦UserControl被删除在容器页面上,我如何从用户控件的代码隐藏处对容器页面的代码隐藏执行某些操作?b $ b $ User例如,假设UserControl在容器页面上的Multiview控件的一个Views中被删除了

。通过

点击取消按钮UserControl的按钮,我想更改容器页面的Multiview控件的

活动视图。


如何在ASP中完成.NET 2.0?


在此先感谢,


-Benton
Hi there,

I have a UserControl with a couple of textboxes and a couple of buttons
("Save" and "Cancel"). The Click event for this buttons is in the
UserControl''s codebehind of course, so here''s my question.

Once the UserControl is dropped onto the container page, how can I perform
some action on the codebehind of the container page from the codebehind of
the UserControl? For instance, suppose that the UserControl is dropped
inside one of the Views of a Multiview control on the container page. By
clicking the "Cancel" button of the UserControl, I would like to change the
active view of the container page''s Multiview control.

How can this be done in ASP.NET 2.0?

Thanks in advance,

-Benton


Benton,


听起来你希望页面告诉用户控件做某事,或者至少设置一个值可以使用。


我所做的是在用户控件上创建一个公共属性。这暴露了我可以为行为设置的

值。然后在用户控件的Load或甚至PreRender事件

处理程序中,您可以使用该属性来控制

行为。


我不会做的是在用户控件上设置一个方法,因为这个
是一个事件驱动的模型。您将希望留在该事件驱动

模型中,让用户控件响应属性,就像使用

控件一样,如TextBox和ListBox。你只需调整那些

控件的属性。


Brennan Stehling
http://brennan.offwhite.net/blog/

Benton写道:
Benton,

It sounds like you want the Page to tell the User Control to do
something, or to at least set a value it can use.

What I do is create a public property on User Controls. That exposes a
value I can set for behavior. Then in the Load or even PreRender event
handler for the User Control you can use that property to control
behavior.

What I would not do is set up a method on the User Control because this
is an event driven model. You will want to stay in that event driven
model and let the User Control respond to properties as you do with
controls like TextBox and ListBox. You just adjust properties on those
controls as well.

Brennan Stehling
http://brennan.offwhite.net/blog/

Benton wrote:

你好,


我有一个带有几个文本框和几个按钮的UserControl

( 保存和取消)。这个按钮的Click事件当然是在

UserControl的代码隐藏中,所以这是我的问题。


一旦UserControl被删除在容器页面上,我如何从用户控件的代码隐藏处对容器页面的代码隐藏执行某些操作?b $ b $ User例如,假设UserControl在容器页面上的Multiview控件的一个Views中被删除了

。通过

点击取消按钮UserControl的按钮,我想更改容器页面的Multiview控件的

活动视图。


如何在ASP中完成.NET 2.0?


在此先感谢,


-Benton
Hi there,

I have a UserControl with a couple of textboxes and a couple of buttons
("Save" and "Cancel"). The Click event for this buttons is in the
UserControl''s codebehind of course, so here''s my question.

Once the UserControl is dropped onto the container page, how can I perform
some action on the codebehind of the container page from the codebehind of
the UserControl? For instance, suppose that the UserControl is dropped
inside one of the Views of a Multiview control on the container page. By
clicking the "Cancel" button of the UserControl, I would like to change the
active view of the container page''s Multiview control.

How can this be done in ASP.NET 2.0?

Thanks in advance,

-Benton


听起来你希望页面告诉用户控件执行
It sounds like you want the Page to tell the User Control to do

某事,或者至少设置一个可以使用的值。
something, or to at least set a value it can use.



实际上它正好相反:我希望UserControl告诉其容器

页面在某些事情发生时做某事。在UserControl本身,

即,当一个按钮在用户控件上点击
时,容器页面应该切换活动视图。


感谢任何提示,


-Benton

Actually it''s the opposite: I want the UserControl to tell its container
page to do something when "something happens" in the UserControl itself,
i.e., the container page should switch the active view when a button is
clicked on the UserControl.

Thanks for any hint,

-Benton


我所做的是在用户控件上创建一个公共属性。这暴露了我可以为行为设置的

值。然后在用户控件的Load或甚至PreRender事件

处理程序中,您可以使用该属性来控制

行为。


我不会做的是在用户控件上设置一个方法,因为这个
是一个事件驱动的模型。您将希望留在该事件驱动

模型中,让用户控件响应属性,就像使用

控件一样,如TextBox和ListBox。你只需调整那些

控件的属性。


Brennan Stehling
http://brennan.offwhite.net/blog/

Benton写道:
What I do is create a public property on User Controls. That exposes a
value I can set for behavior. Then in the Load or even PreRender event
handler for the User Control you can use that property to control
behavior.

What I would not do is set up a method on the User Control because this
is an event driven model. You will want to stay in that event driven
model and let the User Control respond to properties as you do with
controls like TextBox and ListBox. You just adjust properties on those
controls as well.

Brennan Stehling
http://brennan.offwhite.net/blog/

Benton wrote:

>嗨那里,

我有一个带有几个文本框和几个按钮的UserControl
(保存和取消])。这个按钮的Click事件当然是在
UserControl的代码隐藏中,所以这是我的问题。

一旦UserControl被放到容器页面上,我怎么能
从UserControl的代码隐藏对容器页面的代码隐藏执行一些操作?例如,假设UserControl在容器页面上的Multiview控件的其中一个视图内被删除。点击取消按钮UserControl的按钮,我想改变容器页面的Multiview控件的活动视图。

如何在ASP.NET 2.0中完成?

提前致谢,

-Benton
>Hi there,

I have a UserControl with a couple of textboxes and a couple of buttons
("Save" and "Cancel"). The Click event for this buttons is in the
UserControl''s codebehind of course, so here''s my question.

Once the UserControl is dropped onto the container page, how can I
perform
some action on the codebehind of the container page from the codebehind
of
the UserControl? For instance, suppose that the UserControl is dropped
inside one of the Views of a Multiview control on the container page. By
clicking the "Cancel" button of the UserControl, I would like to change
the
active view of the container page''s Multiview control.

How can this be done in ASP.NET 2.0?

Thanks in advance,

-Benton


这篇关于UserControl可以对托管页面代码隐藏执行某些操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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