I have a user control that is loaded only in certain instances, for example, when a user clicks a button on the page the following happens:
MyControl ctl = (MyControl)LoadControl(controlPath);
this.MyFormControl.Add(ctl);
The user control that is loaded has a form and a submit button, with a method that I want to run on click so:
<asp:Button runat="server" ID="SaveButton" Text="Save" OnClick="btnSave_Click" />
In the codebehind of the user control:
protected void btnSave_Click(object sender, EventArgs e)
{
// Do something
}
I can't seem to get the do something part to happen when the button is clicked. I think it may be related to the fact that the control is not normally loaded with the page, but I'm not really sure what to do about that.