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);
}
}
When you trigger a server-side method in an
UpdatePanelASP.NET does the following:within the panel from scratch by
running through the normal ASP.NET
page lifecycle (well, slightly
abridged, but close).
to the client.
client using javascript DOM
manipulation.
If there’s an unhandled
Exceptionduring the first step, the AJAX call fails and it cannot update the originating panel. Here’s a diagram from the ASP.NET AJAX web site:Consider what would happen if you threw an unhandled
ExceptioninPage_Load. ASP.NET wouldn’t be able to finish constructing your HTML in that case, and it cannot do so here.