首先,我的环境:
.NET 2.0
AJAX 更新面板也用于 Web 部件区域。
我有一个主页和默认页面。
默认页面有 WPM 和两个区域。
每个 Web 部件只是一个外壳,并且用户控件用于 A 和 B
我有两个 Web 部件,A 和 B B.(用户控件)- A 有许多按钮。
B 有一个列表框 & 填充列表框并刷新也位于(Web 部件 B 内)包裹列表框的 UpdatePanel 的子控件。
我想单击 Web 部件 A 中的一个按钮,它会在 Web 部件 B 中触发一个名为“Public Sub FillList()”的子项,我似乎无法弄清楚如何执行此操作。
我查找了 webpart 连接,我知道我可以传递属性,这很好,但我想调用 subs/fire 事件。
提前致谢!
First off, my Environment:
VB.NET .NET 2.0
AJAX Update Panels also used around webpart zones.
I have a masterpage and default page.
Default page has WPM and two Zones.
each webpart is just a shell and a usercontrol is used for A & B
I have two webparts, A & B. (Usercontrols)- A has a number of buttons.
B has a listbox & Subs which populate the listbox and refresh the UpdatePanel that also sits (inside the webpart B) wrapping the listbox.
I want to click a button in webpart A and it fires a sub in webpart B called 'Public Sub FillList()' I cant seem to workout how to do this.
I have looked up webpart connects and I understand that I can pass properties which is fine, but I want to call subs/fire events.
Thanks in advance!
发布评论
评论(2)
这听起来像是“事件冒泡的情况”。
事件冒泡允许某些容器的组成控件将其事件“冒泡”或引发以由父(容器)控件处理。
Web 部件 A 中的按钮控件的单击事件中可以包含以下代码:
其中 args 是从 System.EventArgs 派生的某种自定义类型。 然后,这将在父容器(在您的情况下是 UserControl 本身)上引发(或“冒泡”)事件(使用您的自定义参数)。 这是在父容器上的以下事件中处理的:
这可以在网页内的包含层次结构中重复(页面是最终容器)。 一旦此事件到达作为两个用户控件(A 和 B)的父容器的容器,您就可以从父容器的代码中调用 UserControl B 上的公共方法,并根据需要传入自定义事件参数。
This sounds like a case for "event bubbling".
Event bubbling allows a constituent control of some container to have it's events "bubbled" or raised up to be handled by the parent (container) control.
Your button control in Webpart A can have the following code within it's click event:
where args is some custom type deriving from System.EventArgs. This will then raise (or "bubble") the event (with your custom args) on the parent container (in your case the UserControl itself). This is handled within the following event on the parent container:
This can be repeated up the containment hierarchy within your webpage (with the page being the ultimate container). Once this event has reached a container that is the parent of both of your usercontrols (A & B), you can then call public methods on UserControl B from within the code for the parent container, passing in the custom eventargs if you wish.
我知道它有点脏,但我找到了一个可行的解决方案:
我调用的方法是“updateList()”
I know its a bit dirty but I found a solution which kinda works:
The method I call is 'updateList()'