如下TextBox

<asp:textboxonkeypress="isnum()"id="TextBox1"runat="server"></asp:textbox>

<script language="javascript">
function isnum()
{
if(event.keyCode<45||event.keyCode>57)
{
event.keyCode=0;
}
}
</script>

2. 在代码中添加

try
{
Convert.ToDouble(TextBox1.Text.Trim());
}
catch
{
Response.Write(" ");
TextBox1.Text="";
Page.RegisterStartupScript("focus"," ");
}