asp.net text box (textbox) calculation, to determine whether the input is a digital _ practical skills

Source: Internet
Author: User
Copy Code code as follows:

protected void Txtqty_textchanged (object sender, EventArgs e)
{
Checkform ();
}
Verify that the text information is legal and start the calculation if it is valid
protected void Checkform ()
{
Try
{
if (! Isnumberic (txtqty.text) && txtqty.text!= "")
{
Checkbool = false;
Response.Write ("<script>alert" number can only be a number, please enter digital information, thank you for your cooperation!) ') </script> ");
Txtqty.text = "";
Txtqty.focus ();
}
else if (Txtqty.text!= "")
{
Qty = Int. Parse (Txtqty.text);
}
if (! Isnumberic (txtvat.text) && txtvat.text!= "")
{
Response.Write ("<script>alert" is only a number, please enter digital information, thank you for your cooperation!) ') </script> ");
Checkbool = false;
Txtvat.text = "";
Txtvat.focus ();
}
else if (Txtvat.text!= "")
{
Vat = Double.Parse (Txtvat.text);
}
if (! Isnumberic (txtunitprice.text) && txtunitprice.text!= "")
{
Response.Write ("<script>alert" price can only be a number, please enter digital information, thank you for your cooperation!) ') </script> ");
Checkbool = false;
Txtunitprice.text = "";
Txtunitprice.focus ();
}
else if (Txtunitprice.text!= "")
{
UnitPrice = Double.Parse (Txtunitprice.text);
}
if (Checkbool = = True)
{
if (Vat!= 0 && exvatamount!= 0)
{
Amountvat = Exvatamount/(1-vat/100);
Txtamountvat.text = Amountvat.tostring ();
}
}
}
catch (Exception ex)
{
Console.WriteLine (ex. message);
}
}
<summary>
Name: Isnumberic
Function: To determine whether the input is a number
Parameters: String Otext: Source text
return value: BOOL true: Yes false: No
</summary>
public bool Isnumberic (string otext)
{
Try
{
Conversion from string to double, string to double, return true if successful, or false.
Double var1 = convert.todouble (Otext);
return true;
}
Catch
{
return false;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.