单击自定义控制按钮的事件处理程序

时间:2010-07-19 17:27:49

标签: vb.net event-handling asp.net-3.5 custom-controls onclick

我正在为我的Web应用程序创建一个ASP.NET自定义控件,它基本上是一个包含在多个<div>元素中的ASP.NET Button控件(用于样式目的)。

如何为自定义控件创建Click事件处理程序,以便我的控件充当ASP.NET按钮?

<cc:Button id="myButton" runat="server" Text="Submit" />

Sub myButton_Click(sender as object, e as EventArgs) Handles myButton.Click

End Sub

2 个答案:

答案 0 :(得分:4)

在后面的代码中,在您的类中声明一个事件:

Public Event Click(sender as object, e as EventArgs)

然后,当您处理constinuent按钮的click事件时,请引发事件

Sub btnButton_Click(sender as object, e as EventArgs) Handles btnButton.Click
    RaiseEvent Me.Click(Me, EventArgs)
End Sub

答案 1 :(得分:0)

伟大的片段,非常方便用户控制提升需要通知父屏幕的事件。我的通用表格是这样的:

Public Event eventTrigger(ByVal sender As Object, ByVal e As EventArgs)

Private Sub ucUserControl_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtText1.TextChanged, txtText2.TextChanged,txtetc.TextChanged

    RaiseEvent eventTrigger(Me, e)

End Sub