You have two main options for achieving this, either by requiring the user of the control to provide an upload method that is called by your control when the Upload button is clicked, or you can require that the control is sub-classed, and the Upload
method implemented.
Method 1 - Providing a delegate to be called upon upload:
public partial class MyControl
{
// Define a delegate that specifies the parameters that will be passed to the user-provided Upload method
public delegate void DoUploadDelegate(... parameters ...);
private readonly DoUploadDelegate _uploadDelegate;
public MyControl(DoUploadDelegate uploadDelegate)
{
if (uploadDelegate == null)
{
throw new ArgumentException("Upload delegate must not be null", "uploadDelegate");
}
_uploadDelegate = uploadDelegate;
InitializeComponent();
}
// ...
// Upload button Click event handler
public void UploadButtonClicked(object sender, EventArgs e)
{
// Call the user-provided upload handler delegate with the appropriate arguments
_uploadDelegate(...);
}
}
Method 2 - Require the upload method to be overridden:
public abstract partial class MyControl
{
private readonly DoUploadDelegate _uploadDelegate;
protected MyControl()
{
InitializeComponent();
}
// ...
// The method that users of the control will need to implement
protected abstract void DoUpload(... parameters ...);
// Upload button Click event handler
public void UploadButtonClicked(object sender, EventArgs e)
{
// Call the overridden upload handler with the appropriate arguments
DoUpload(...);
}
}
For the latter option, a user would need to sub-class the control before being able to use it, as follows:
public class MyConcreteControl : MyControl
{
protected override void DoUpload(... parameters ...)
{
// User implements their own upload logic here...
}
}