How can I "bubble" up an event from a usercontrol to the main page? However the usercontrol is not always loaded as I am using update panels to ajax in different usercontrols.
I have found this but it assumes the usercontrol is always loaded?
Edit: I looked at tutorials but for some reason it takes two for the event work.
This is the button to be pressed and its code behind callback
<asp:button runat="server" ID="profileSignOut" CssClass="btn btn-default" OnClick="profileSignOut_Click" Text="Sign Out"/>
protected void profileSignOut_Click(object sender, EventArgs e)
{
infoTB.Text += "\nclicked";
Session.Clear();
Session.Abandon();
if (SignOut != null)
SignOut(this, EventArgs.Empty);
}
The event defined in the usercontrol, had to be static otherwise the event handler in the main page would throw an error
public static event EventHandler SignOut;
and the handler in the main page
protected void Page_Load(object sender, EventArgs e)
{
Views.Profile.SignOut += new EventHandler(signOutEvent);
LoadUserControl();
}
private void signOutEvent(Object sender, EventArgs e)
{
MenuButtons.Visible = true;
LastLoadedControl = null;
LoadUserControl();
}