Cancel User control action based on user input on page
Posted on 2011-09-02
I have an ASP.NET page containing a fairly complex user control (comprised of a lot of other controls) and a panel that starts invisible and acts as a pop-up confirmation window (I set the visible property to true, and then when a button on the panel is clicked set it back to false.)
There is a button in the user control that acts as a 'save' button, committing any changes made in the control to the database, and another that cancels changes and reverts the control to the original state. I want to have the popup on the page appear when the cancel button is clicked, and then only revert the control to the original state if the users confirms that this is what they want.
I can achieve this by putting the popup panel within the user control rather than on the page, but this will mean duplicating the panel a LOT of times in other controls, and I also want the page to perform other actions when the user confirms the cancellation on the popup.
I can also achieve this by firing a 'cancelling' event in the control, and handling it with the page, and then the page can call a 'revert' method in the control if the user confirms the cancel with the popup, but this will tie the page and the control together so that any other page using the control would have to implement the popup. I want to make sure that the control can be used without a confirmation box if I don't want one.
To summarise: I want to have a control that fires an event when the cancel button in the control is clicked, and then only continues and reverts the control to default values if the event is not handled or if it is handled but the page allows the operation to continue (based on user input or whatever else)
I think this can be achieved using a custom Eventargs class containing a 'continue' field that can be set by the page, but the problem is that there has to be another postback in between.
Hope that isn't too confusing. I'm afraid i can't post the code because there is too much of it and some of it isn't mine.