Reputation: 785
I am converting a vb user control to c#. I don't remember how to bind an event to a control in c#. In vb its pretty straight forward with the Handles clause:
Protected Sub Control_PreRender(Sender As Object, e As EventArgs) Handles Me.PreRender
I cannot seem to work out how to do this in c# short of just creating the method and hope it links itself. Is this the way to go?
public void Control_PreRender(object sender, EventArgs e)
Upvotes: 1
Views: 2043
Reputation: 32068
You got it almost right, the only problem is that events don't auto-attach themselves. You need to add this to the constructor of the control:
public MyControl()
{
// your current code
PreRender += Control_PreRender;
}
Upvotes: 2