ASp.net 文本框(TextBox)計算,判斷輸入的是否是數(shù)字
更新時間:2009年07月13日 20:41:45 作者:
ASp.net文本計算,文本框數(shù)字輸入檢測,文本框的TextChanged事件,同時在屬性的Auto Post Back設置為True
復制代碼 代碼如下:
protected void txtQty_TextChanged(object sender, EventArgs e)
{
checkForm();
}
//檢驗文本信息是否合法,如果合法則開始計算
protected void checkForm()
{
try
{
if (!IsNumberic(txtQty.Text) && txtQty.Text != "")
{
checkbool = false;
Response.Write("<script>alert('數(shù)量只能為數(shù)字,請輸入數(shù)字信息,謝謝合作!')</script>");
txtQty.Text = "";
txtQty.Focus();
}
else if (txtQty.Text != "")
{
Qty = int.Parse(txtQty.Text);
}
if (!IsNumberic(txtVat.Text) && txtVat.Text != "")
{
Response.Write("<script>alert('稅額只能是數(shù)字,請輸入數(shù)字信息,謝謝合作!')</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('價格只能是數(shù)字,請輸入數(shù)字信息,謝謝合作!')</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>
/// 名稱:IsNumberic
/// 功能:判斷輸入的是否是數(shù)字
/// 參數(shù):string oText:源文本
/// 返回值: bool true:是 false:否
/// </summary>
public bool IsNumberic(string oText)
{
try
{
//從字符串到雙精度值的轉(zhuǎn)換,字符串轉(zhuǎn)換為Double,如果成功則返回為真,否則返回為假。
Double var1 = Convert.ToDouble(oText);
return true;
}
catch
{
return false;
}
}
}
您可能感興趣的文章:
- ASP.NET?MVC5網(wǎng)站開發(fā)之添加、刪除、重置密碼、修改密碼、列表瀏覽管理員篇2(六)
- ASP.NET MVC5網(wǎng)站開發(fā)用戶修改資料和密碼(六)
- asp.net利用cookie保存用戶密碼實現(xiàn)自動登錄的方法
- ASP.NET 回發(fā)密碼框清空問題處理方法
- 解讀ASP.NET密碼強度驗證代碼實例分享
- asp.net 生成隨機密碼的具體代碼
- asp.net中使用cookie與md5加密實現(xiàn)記住密碼功能的實現(xiàn)代碼
- 淺析ASP.NET生成隨機密碼函數(shù)
- asp.net membership 密碼重設
- ASP.net中md5加密碼的方法
- ASP.NET jQuery 實例13 原創(chuàng)jQuery文本框字符限制插件-TextArea Counter
- ASP.NET文本框密碼賦默認值的方法
相關文章
Asp.Mvc 2.0實現(xiàn)用戶登錄與注銷功能實例講解(2)
這篇文章主要介紹了Asp.Mvc 2.0實現(xiàn)用戶登錄與注銷功能,用戶登錄方式都是FORM表單驗證方式,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-08-08ASP.NET Core開發(fā)教程之Logging利用NLog寫日志文件
一直很喜歡 NLog 的簡潔和擴展性,所以下面這篇文章主要給大家介紹了關于ASP.NET Core開發(fā)教程之Logging利用NLog寫日志文件的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2018-07-07LINQ字符串向datetime 轉(zhuǎn)換時失敗的處理方法
LINQ字符串向datetime 轉(zhuǎn)換時失敗的處理方法,需要的朋友可以可以參考一下2013-03-03