title: How to show message box after uploading a file which size is bigger than limit size instead of showing IE page error
body: <p>In my project, I have FileUpload control and upload button. I want to limit the file size at 10MB so I put the following code in web.config.</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;httpRuntime executionTimeout="240" maxRequestLength="10240" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>I also put try/catch block in upload button click method as follows:</p>
  
  <pre><code>Private Sub Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Attach.Click
      Try
          If FileUpload1.HasFile Then
              Dim fileSize As Integer = FileUpload1.PostedFile.ContentLength
              If (fileSize &lt; 10485760) Then
                  Select_id = ViewState("Select_id")
                  typename = CInt(ViewState("typename"))
                  If Select_id.HasValue Then
                      UploadFile(FileUpload1.PostedFile)
                  End If
              Else
                  ShowMessageBox(Me.Parent.Page, "File size cannot be greater than 10MB.")
              End If
          End If
      Catch ex As Exception
          ShowMessageBox(Me.Parent.Page, ex.Message)
      End Try
  End Sub
  </code></pre>
  
  <p>As I tested the function, it works correctly for the file which size is less than 10MB. In contrast, the file which size is greater than 10MB cause page error, stating that "Internet Explorer cannot display the webpage". It didn't even enter the button click method when I tried debugging.</p>
  
  <p>Right now, it is not really a big problem. I just want to know how to show message box of error instead of redirecting to IE error page. If there is no solution for this, I'll just leave it be.</p>