views:

19

answers:

1

I'm creating an ASP.NET Custom Control for my web application which is basically an ASP.NET Button control contained inside multiple <div> elements (for styling purposes).

How can I create a Click event handler for my custom control so that my control acts as an ASP.NET Button?

Ie.

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

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

End Sub
+2  A: 

In the code behind, declare an event in your class:

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

Then when you handle the click event for the constinuent button, raise the event

Sub btnButton_Click(sender as object, e as EventArgs) Handles btnButton.Click
    RaiseEvent Me.Click(Me, EventArgs)
End Sub
Bill
Had to make a slight change, but apart from that, worked perfectly!Sub btnButton_Click(sender as object, e as EventArgs) Handles btnButton.Click RaiseEvent Click(Me, e)End Sub
Curt