When trying to upload an Image, I push the button and the page refreshes and the image doesn't upload. What is going on?
<p>I have a webform that inherits the layout from a Site.Master file. Everytime I press the "Upload" Button, the page refreshes and nothing happens. I just want it to upload the image from the "FileUpload" Control. I have used this exact code on a page that does not inherit a layout from a Site.Master but I need this to work with a Site. Master. Any ideas?</p>

<p>Here's the ASP Part:</p>

<pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="SignUp.aspx.cs" Inherits="MTCO.SignUp" %&gt;
&lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
    &lt;asp:TextBox ID="firstNameBox" runat="server"&gt;&lt;/asp:TextBox&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;asp:TextBox ID="lastNameBox" runat="server"&gt;&lt;/asp:TextBox&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;asp:Button ID="uploadButton" runat="server" Text="Upload" /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;asp:TextBox ID="statusBox" runat="server"&gt;In Progress..&lt;/asp:TextBox&gt;
    &lt;br /&gt;
&lt;/asp:Content&gt;
</code></pre>

<p>And Heres the C# Part:</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MTCO
{
    public partial class SignUp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void uploadButton_Click(object sender, EventArgs e)
        {
            string filePath = Server.MapPath("~/images/testing/") + FileUpload1.FileName;
            Bitmap photoFile = ResizeImage(FileUpload1.PostedFile.InputStream, 200, 300);
            photoFile.Save(filePath, ImageFormat.Jpeg);
            statusBox.Text = "Uploaded Successfully";
        }

        public Bitmap ResizeImage(Stream stream, int? width, int? height)
        {
            System.Drawing.Bitmap bmpOut = null;
            const int defaultWidth = 800;
            const int defaultHeight = 600;
            int lnWidth = width == null ? defaultWidth : (int)width;
            int lnHeight = height == null ? defaultHeight : (int)height;
            try
            {
                Bitmap loBMP = new Bitmap(stream);
                ImageFormat loFormat = loBMP.RawFormat;

                decimal lnRatio;
                int lnNewWidth = 0;
                int lnNewHeight = 0;

                //*** If the image is smaller than a thumbnail just return it
                if (loBMP.Width &lt; lnWidth &amp;&amp; loBMP.Height &lt; lnHeight)
                {
                    return loBMP;
                }

                if (loBMP.Width &gt; loBMP.Height)
                {
                    lnRatio = (decimal)lnWidth / loBMP.Width;
                    lnNewWidth = lnWidth;
                    decimal lnTemp = loBMP.Height * lnRatio;
                    lnNewHeight = (int)lnTemp;
                }
                else
                {
                    lnRatio = (decimal)lnHeight / loBMP.Height;
                    lnNewHeight = lnHeight;
                    decimal lnTemp = loBMP.Width * lnRatio;
                    lnNewWidth = (int)lnTemp;
                }

                bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
                Graphics g = Graphics.FromImage(bmpOut);
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
                g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
                loBMP.Dispose();
            }
            catch
            {
                return null;
            }
            return bmpOut;
        }
    }
}
</code></pre>
