I have a LinkButton within a User Control and it has handled with:
Private Sub LoginLinkLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginLinkLinkButton.Click
Response.Redirect("/", True)
End Sub
On certain ASPX pages I would like to handle the click from the page’s code behind, opposed to within the user control. How do I override the handle within the control from the parent’s code behind page?
Update:
Based on the answer, I have the updated the User Control:
Public Event LoginLinkClicked As OnLoginClickHandler
Public Delegate Sub OnLoginClickHandler(ByVal sender As Object, ByVal e As EventArgs)
[...]
Private Sub LoginLinkLinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginLinkLinkButton.Click
**If OnLoginClickHandler IsNot Nothing Then**
RaiseEvent LoginLinkClicked(Me, e)
Else
Response.Redirect("/", True)
End If
End Sub
The problem is determining the correct syntax for the if line because the above is invalid.
You’ll have to expose a new event from the user control. Apologies as the following code is all in C# and it’s been a long time since I touched VB.Net, but you should get the idea:
You can use a delegate event by adding the following to your
UserControl:Then call the following to your LinkButton
Clickevent:You can then just hook up into this within your aspx markup:
And your server side event handler on your Page will be as follows:
UPDATE
I think this is how you translate the event subscription check to VB.Net: