Reputation: 85
I created a custom event to fire when a button is clicked on my usercontrol. I want to capture this event on my parent aspx page. I've tried numerous methods from searching the web, but none seem to work. Any suggestions?
'my usercontrol code behind
Public Event DButtonClick As EventHandler
Protected Sub Button7_Click(sender As Object, e As System.EventArgs) Handles Button7.Click
RaiseEvent DButtonClick(sender, e)
Response.Write("1112333022")
DeleteUser(ListBox1.SelectedItem.Value)
End Sub
'aspx code behind
Protected Sub AdminEdit1_DButtonClick(sender As Object, e As EventArgs) Handles AdminEdit1.DButtonClick
Response.Write("page")
End Sub
Upvotes: 1
Views: 1290
Reputation: 26386
Try to register the event handler in the code-behind of the parent page instead of through the markup
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler AdminEdit1.DButtonClick, AddressOf AdminEdit1_DButtonClick
End Sub
I use C# and I am not sure if the above VB syntax correct, to verify, here is C# equivalent
public void Page_Load(object sender, EventArgs e)
{
AdminEdit1.DButtonClick += new EventHandler(AdminEdit1_DButtonClick);
}
Sometimes it does not work from setting it from the markup as I had experienced in the past and I can not tell you why.
Upvotes: 1