好的,在摆弄了 2 天之后,我终于得出结论,我根本不了解事件。
这是我正在尝试做的事情,然后是我的代码:
我的用户控件中有一个按钮,单击后,我想更新 .aspx 页面中的标签。所以我在我的用户控件中创建了一个事件处理程序,我试图在我的页面中监听它。但它根本不起作用,我希望有人能启发我。
用户控制:
Public Custom Event handleButtonEvent As EventHandler
AddHandler(ByVal value As EventHandler)
AddHandler btnEventCall.Click, AddressOf Me.doStuff
End AddHandler
RemoveHandler(ByVal value As EventHandler)
RemoveHandler btnEventCall.Click, AddressOf Me.doStuff
End RemoveHandler
RaiseEvent (ByVal sender As Object, ByVal e As System.EventArgs)
End RaiseEvent
End Event
Protected Sub btnEventCall_Click(sender As Object, e As EventArgs) Handles btnEventCall.Click
End Sub
Protected Sub doStuff()
Response.Write("do stuff") 'dont really need this
End Sub
.aspx 页面:
Protected Sub control_event(ByVal sender As Object, ByVal e As EventArgs) Handles test1a.handleButtonEvent
updateLabel()
End Sub
private sub updateLabel()
lblUpdate.Text="works!"
end sub
谢谢!