I am trying to change a value in the event arguments. Not sure if this is possible, but this is my current event in the parent class:
public void MasterClass()
{
void btnSubmit_Click(object sender, EventArgs e)
{
...
OnInputBound(this, new InputEventArgs(postName, value));
//I would like to try something like this but does not work:
//value = OnInputBound(this, new InputEventArgs(postName, value));
//Continue with new value...
}
}
In other parts of the application, they register the event normally like this:
protected override void CreateChildControls()
{
MyForm.OnInputBound += new EventHandler<InputEventArgs>(MyForm_OnInputBound);
}
void MyForm_OnInputBound(object sender, SingleForm.InputEventArgs e)
{
e.Value = "new value";
}
Notice how I am trying to change the argument for the MasterClass. This is obviously not working, but how would I bubble this value up?
You will need to hold on to a reference to the
InputEventArgsinstance so that you can read theValuefrom it after the event has been raised:One thing to be aware of here is that there are scenarios that may lead to unexpected results:
Take the following case for instance (first point above):
In this case there is no guarantee that the value is assigned before your code in
btnSubmit_Clickpicks up the “new” value from theInputEventArgsinstance.