title: Triggering a SUBMIT in an asp.net application
body: <p>I need to trigger a submit when saving my image file in SQL 2005 database.  </p>
  
  <p>A user will upload their image file.<br>
  My application will then check to see if the image file size is within specific requirements.<br>
  If so, then save the image into a table where the field is image data type. (if size does not meet requirements, display error message and exit sub).  </p>
  
  <p>The issue is if I save the image file to the database, the value is saved correctly (however, I have not checked the image size).  </p>
  
  <p>If I check the image file size first, THEN save it, the value saved is corrupted (incorrect).  </p>
  
  <p>Is there a way that I can check the file size, then save the file while doing a submit in code-behind?  </p>
  
  <p><strong>My code is below:</strong>  </p>
  
  <pre><code>            Dim iRequiredImageHeight As Integer = 80
              Dim iRequiredImageWidth As Integer = 280
  
              Dim imgBytes(FileUpload1.PostedFile.InputStream.Length) As Byte
              Dim stream As System.IO.Stream = FileUpload1.PostedFile.InputStream
              stream.InitializeLifetimeService()
              stream.Read(imgBytes, 0, imgBytes.Length)
  
              Dim imgData As System.Drawing.Image = System.Drawing.Image.FromStream(stream)
              Dim imgWidth As Integer = imgData.PhysicalDimension.Width
              Dim imgHeight As Integer = imgData.PhysicalDimension.Height
  
              If imgHeight &gt; iRequiredImageHeight Or imgHeight &gt; iRequiredImageWidth Then
                  lblLogoMessage.Text = "The image you have uploaded is " &amp; imgHeight &amp; "px height by " &amp; imgWidth &amp; "px width. &lt;br/&gt; Required image size is " &amp; iRequiredImageHeight &amp; "px height by " &amp; iRequiredImageWidth &amp; "px width. &lt;br/&gt; Please resize the image and try again."
                  lblLogoMessage.ForeColor = Drawing.Color.Red
                  lblLogoMessage.Visible = True
                  bLogoFit = False
              Else
  
                  Dim LogoFile As String = FileUpload1.FileName.ToString.Trim
                  Dim FileBytes(FileUpload1.PostedFile.InputStream.Length) As Byte
  
                  FileUpload1.PostedFile.InputStream.Read(FileBytes, 0, FileBytes.Length)
  
                  Dim SQL As String = "update CorpLogo "
                  SQL += "set HeaderLogoName = @LogoFile, LogoImage = @LogoBytes "
                  SQL += " where isonum='100'"
  
                  Dim myConn As New SqlConnection(connString)
                  Dim SQLcmd As New SqlCommand(SQL, myConn)
                  SQLcmd.Parameters.AddWithValue("@LogoFile", LogoFile)
                  SQLcmd.Parameters.AddWithValue("@LogoBytes", FileBytes)
  
                  myConn.Open()
                  SQLcmd.ExecuteNonQuery()
                  myConn.Close()
              End If
  </code></pre>