When a menu item is clicked in my menu an ASCX control is loaded via AJAX in my asp panel. To do this I have a method:
public void LoadControl(ControlDestination controlDestination, string filename)
{
try
{
// Load control from file
Control control = LoadControl(filename);
// Check control extends BaseForm
// Do stuff
}
else
{
throw new Exception("Web User Control erft niet van BaseForm.");
}
}
catch (ArgumentNullException e)
{
// Implement
}
catch(HttpException e)
{
LoadControl(ControlDestination.Menu, "Error.ascx");
throw new Exception("User control niet gevonden: " + e.ToString());
}
}
When I set a breakpoint at the HttpException I get there. I press F11 and the code in LoadControl is executed. Then the excetpion pops up. All this goes well, but Error.ascx is never loaded. I know the method is working because when I want to load other ASCX objects via this method it works. But When I want to load Error.ascx is goes wrong.
I can see Error.ascx if I comment out throw new Exception("User control niet gevonden" + e.ToString()); I want both lines to be executed.
EDIT:
In my master page I have this javascript code to catch some exceptions:
function pageLoad() {
var manager = Sys.WebForms.PageRequestManager.getInstance();
manager.add_endRequest(endRequest);
manager.add_beginRequest(beginRequest);
}
function endRequest(sender, args){
var Error = args.get_error();
if (Error != null) {
ToggleErrorOn(true);
document.getElementById("ErrorContent").innerHTML = Error.message;
args.set_errorHandled(true);
}
}