Deriving a class from TextBox class
<p>I am attempting to derive a custom class called NumBox from the TextBox class and create a setter and getter for this class, but when I run my program I get a run time exception "FormatException was unhandled by user code".  It appears to me that this has to do with this.Text not being an integer, but the input for my program was an int.  The error occurs on the following line:  <code>return Convert.ToInt16(this.Text);</code></p>

<p>Thanks you for the help!</p>

<p>Please find my code below:
default.aspx</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;glm:numbox ID="NumBox1" runat="server" Style="position: relative" /&gt;
        &lt;asp:Button ID="Button_SquareIt" runat="server" Style="position: relative" 
            Text="Square It" onclick="Button_SquareIt_Click" /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>webconfig</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  --&gt;
&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;compilation debug="true" targetFramework="4.0"/&gt;
        &lt;pages&gt;
            &lt;controls&gt;
                &lt;add tagPrefix="glm" namespace="GLM"/&gt;
            &lt;/controls&gt;
        &lt;/pages&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;
</code></pre>

<p>App_Code/NumBox.cs</p>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// &lt;summary&gt;
/// Summary description for Class1
/// &lt;/summary&gt;
/// 
namespace GLM
{
    public class NumBox : TextBox
    {
        public NumBox()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int Num
        {
            set
            {
                this.Text = value.ToString();
            }
            get
            {
                return Convert.ToInt16(this.Text);
            }
        }
    }
}
</code></pre>

<p>default.aspx.cs</p>

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

public partial class _Default : System.Web.UI.Page
{
    GLM.NumBox n = new GLM.NumBox();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button_SquareIt_Click(object sender, EventArgs e)
    {
       n.Num = n.Num *  n.Num;
    }
}
</code></pre>
