I need to limit the file size that users can upload on a specific page. To achieve this, I have configured it in web.config
as follows:
<location path="SubSection/TestPage">
<system.web>
<httpRuntime maxRequestLength="2048" />
</system.web>
</location>
However, when an error occurs, it redirects the user to one of those ASP.NET yellow-error pages. I am aware of custom error pages, but they involve browser redirection.
I simply want to notify the user about the oversized file upload without redirecting them from the current page. Is there a way to prevent TestPage from redirecting to the yellow-error page and instead show a JavaScript popup?
I tried handling the error in the Application_Error()
method in the global.asax
file, but it still redirects after the method finishes executing. My attempts to display a JavaScript popup through this method were unsuccessful, although it should be possible in the global.asax
file.
This is the code snippet I used for handling Application_Error()
, following suggestions from here, with the JavaScript integration based on this:
void Application_Error(object sender, EventArgs e)
{
// Code implementation here
}
In addition, I also attempted to include code in the user control itself (in VB.NET
) using advice from this.
Unfortunately, the code did not get triggered at all. Is there a way to handle simple user mistakes like uploading slightly large files without losing user data on the original page by just displaying a JavaScript alert box?