我从动态加载的ascx控件(katalogbooklist.ascx)到它的父控件(ViewAJBarnboksKatalog.ascx)的起泡事件有问题
当事件addMultiVotes_command在chiled控件中触发时,我需要在父控件中触发/运行sub uppdateraAndraModuler。
是否有人知道或知道如何做到这一点?
/ 安德烈亚斯
(代码存在于dotnetnuke cms模块中,如果有任何帮助的话)
Partial Class ViewAJBarnboksKatalog '<--------Partial codebehind file for ViewAJBarnboksKatalog.ascx
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
.. code for adding for loading katalogbooklist.ascx dynamic...
Me.Controls.Add(..code.. add katalogbooklist.ascx ..) '
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim t As Execkoden = New Execkoden()
AddHandler t.onAjeventtest, AddressOf Uppdateramod
End Sub
Public Sub Uppdateramod(sender As Object, e As ajeventArgs)
uppdateraAndraModuler()
End Sub
Public Sub uppdateraAndraModuler()
'..do some code
End Sub
End Class
Partial Class katalogenBookList '<--------Partial codebehind file for katalogbooklist.ascx
Protected Sub addMultiVotes_command(ByVal sender As Object, ByVal e As System.EventArgs)
'..more code...
Dim te As New Execkoden ' <----- i want to use the constructor to raise the event in class Execkoden can´t raiseevent directly it wont´t fire
'... more code...
End sub
End Class
Public Class ajeventArgs : Inherits EventArgs
Public Sub New()
End Sub
End Class
Public Delegate Sub Uppdatera(sender As Object, e As ajeventArgs)
Public Class Execkoden
Public Event onAjeventtest As Uppdatera
Public Sub New()
RaiseEvent onAjeventtest(Me, New ajeventArgs)
End Sub
End Class
答案 0 :(得分:1)
在子控件中创建一个事件处理程序,如下所示:
public event EventHandler DeleteButtonClick;
在子控件中单击按钮时,请执行以下操作:
protected void DeleteClick(object sender, EventArgs e)
{
if (this.DeleteButtonClick != null)
this.DeleteButtonClick(sender, e);
}
在父控件中,在标记中:
<UC:SomeUserControl ID="UserControl1" runat="server" OnDeleteButtonClick="UserControl1_DeleteClick" ...>
在父控件后面的代码中:
protected void UserControl1_DeleteClick(object sender, EventArgs e)
{
//do something
}
答案 1 :(得分:0)
我建议使用内置于DotNetNuke的IMC或Inter Module Communication功能。