 |
|
ถ้าต้องการให้ textbox ใส่แค่ตัวอักษรได้เท่านั้น ถ้ากดเป็นตัวเลขให้แสดง เมสเสสเตือน |
|
 |
|
|
 |
 |
|
ใช่ JavaScript ครับ
Code (JavaScript)
<script type="text/javascript">
function isCharKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 32 && (charCode < 48 || charCode > 57))
return true;
return false;
}
</script>
|
 |
 |
 |
 |
Date :
2016-06-17 14:22:19 |
By :
taotechnocom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คนที่เค้า มาตอบคำถาม เค้าสังเกตที่ Tag : .NET, Ms SQL Server 2012, Web (ASP.NET), VS 2012 (.NET 4.x)
คุณ p_pat บอกว่า C# นั่นแหละครับ C# เราอ้างอิง Tag มาว่า ASP.NET ทางคุณ TaoZaZa เค้าก็แนะนำ Code ให้ถูกต้องตาม Tag ครับ
เราต้องระบุให้ชัดเจนว่า Window Application , Web Appcliation , ภาษา C# , ภาษา VB.NET บลาๆๆๆ
ด้วยความเคารพ อย่าโกรธกันนะ
|
 |
 |
 |
 |
Date :
2016-06-19 06:45:07 |
By :
bigsuntat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถึงจะเขียน C# แต่เราก้สามารถเขียน java ดักตั้งแต่คีย์ข้อความดักตั้งแต่ฝั่ง aspx ถึงครับ ไม่ต้องไม่เขียนฝั่ง code behide เพื่อป้องกันการคีย์ได้เลย ถ้าคิดว่า ว่าต้องเขียนแต่ c# อย่างเดียวแล้วที่เขาเขียน angular js กับ c# รวมกันละครับทำไมเขียนได้ครับ อันนี้ผมแค่อยากแนะนำเพราะบางอย่างทำได้โดยไม่ต้องไปเขียนฝั่ง c# ก้ได้ครับ แถบ respond กลับ user โคยดักไม่ให้คีย์เลยจากที่เคยเขียนมาและใช้มาครับ
|
 |
 |
 |
 |
Date :
2016-06-19 12:50:23 |
By :
taotechnocom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
@bigsuntat, TaoZaZa
ผมรู้สึกว่าพวกคุณไม่รู้จักคำว่าโต ในเชิงโปรแกรมมิ่ง (ไร้ซึ่งจินนาการ)
ปล. ผมไม่จำเป็นต้องขอโทษใครฯ
|
 |
 |
 |
 |
Date :
2016-06-19 20:40:33 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โถ่ ง่ายๆ
เขียนโปรแกรมไป อ่านนิยายเซ็กไปสิ
อย่าดู av เพราะมันจะไร้ซึ่งจินตนาการ
ปล.คิดถึงเฮัยกังฟู
|
 |
 |
 |
 |
Date :
2016-06-20 08:49:19 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บางครั้งบางคราว "ความโกรธมันทำให้เรื่องดีกลายเป็นร้ายและในทางกลับกัน"

WL_Controls.js
Code (JavaScript)
//<input type="text" onkeypress="return changeToUpperCase(event,this)" />
function changeToUpperCase(event,obj) {
charValue = (document.all) ? event.keyCode : event.which;
if (charValue!="8" && charValue!="0" && charValue != "27"){
obj.value += String.fromCharCode(charValue).toUpperCase();
return false;
}else{
return true;
}
}
function integerOnly() {
var keyCode = event.keyCode;
return (keyCode >= 48 && keyCode <= 57);
}
function numberOnly(obj) {
//if (window.event.keyCode) {
var keyCode = event.keyCode;
if (obj.value.indexOf('.') != -1 && keyCode == 46) {
return false;
}
if (obj.value.indexOf('-') != -1 && keyCode == 45) {
return false;
}
if (obj.value.indexOf('+') != -1 && keyCode == 43) {
return false;
}
if (keyCode >= 48 && keyCode <= 57 || keyCode == 8 || keyCode == 46 || keyCode == 16 || keyCode == 9 || keyCode == 37 || keyCode == 43 || keyCode == 45) {
return true;
}
return false;
//}
}
function formatCurrency(num, ndec) {
num = num.toString().replace(/\$|\,/g, '');
if (isNaN(num))
num = "0";
if (isNaN(ndec))
ndec = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num * 1000000 + 0.50000000001);
cents = num % 1000000;
num = Math.floor(num / 1000000).toString();
if (cents < 10) cents = "00000" + cents
else
if (cents < 100) cents = "0000" + cents
else
if (cents < 1000) cents = "000" + cents
else
if (cents < 10000) cents = "00" + cents
else
if (cents < 100000) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
num1 = cents + "00000";
numx = num1.substring(0, ndec);
if (ndec > 0)
resultn = num + '.' + numx
else resultn = num;
return (((sign) ? '' : '-') + resultn);
}
sample : format(4567354.677623); // 4,567,354.68
*/
function formatCurrency2015(n, sep, decimals) {
sep = sep || "."; // Default to period as decimal separator
decimals = decimals || 2; // Default to 2 decimals
alert(decimals);
return n.toLocaleString().split(sep)[0] + sep + parseFloat(n).toFixed(decimals).split(sep)[1];
}
formatCurrency2016(9.1234567899, 9) --> 9.123456790
*/
function formatCurrency2016(num, decimals) {
var sign = (num >= 0) ? 1 : -1;
//return (Math.round((num * Math.pow(10, decimals)) + (sign * 0.01)) / Math.pow(10, decimals)).toFixed(decimals);
return (Math.round((num * Math.pow(10, decimals)) + (sign * 0.001)) / Math.pow(10, decimals)).toFixed(decimals);
}
WL_TextBox.vb
Code (VB.NET)
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
'<DefaultProperty("Text"), ToolboxData("<{0}:WL_Controls.WL_TextBox1 runat=server></{0}:WL_Controls.WL_TextBox1>")>
<ControlBuilder(GetType(System.Web.UI.WebControls.TextBoxControlBuilder)), Designer("System.Web.UI.Design.ControlDesigner"), DefaultProperty("ID"), ToolboxData("<{0}:WL_TextBox runat=server></{0}:WL_TextBox>")> _
Public Class WL_TextBox
Inherits TextBox
Public Enum InputType
Text
[Integer]
Number
End Enum
Public Enum DisplayDecimal
None
One
Two
Tree
Four
Five
...
...
...
<Bindable(False), Category("Appearance"), DefaultValue(False), Localizable(True), Description("isUpperCase")>
Property _isUpperCase() As Boolean
Get
If ViewState("_isUpperCase") Is Nothing Then
Return False
Else
Return CType(ViewState("_isUpperCase"), Boolean)
End If
'Return DirectCast(ViewState("DisplayAsLiteral"), Boolean)
End Get
Set(ByVal Value As Boolean)
ViewState("_isUpperCase") = Value
End Set
End Property
Protected Overrides Sub RenderContents(writer As System.Web.UI.HtmlTextWriter)
If _DisplayAsLiteral = True Then 'Default Tag Span
Dim x As New Literal() With {.ID = Me.ID}
If _AllowInputType = InputType.Integer Then
If _DisplayComma Then
Me.Text = String.Format("{0:N0}", Val(Me.Text))
End If
ElseIf _AllowInputType = InputType.Number Then
x.Text = Me.Text
End If
x.RenderControl(writer)
Else
MyBase.RenderContents(writer)
End If
End Sub
Protected Overrides Sub OnInit(e As System.EventArgs)
If (_AllowInputType <> InputType.Text) AndAlso (_FormatOnblur = True) Then
If Not MyBase.Page.ClientScript.IsClientScriptIncludeRegistered("WL_Controls_JScript") Then
MyBase.Page.ClientScript.RegisterClientScriptInclude("WL_Controls_JScript", MyBase.Page.ClientScript.GetWebResourceUrl(MyBase.GetType(), "WL_Controls.WL_Controls.js"))
'HttpContext.Current.Response.Write("Not Register WL_Controls JScript ท่านจำเป็นต้องลงทะเบียนเพื่อเสียเงิน" & "<br/>")
End If
If _AllowInputType = InputType.Integer Then
MyBase.Attributes("onkeypress") = "var cv = (document.all) ? event.keyCode : event.which; return (cv >=48 && cv <=57);"
'MyBase.Attributes("onkeypress") = "return integerOnly();"
End If
If _AllowInputType = InputType.Number Then
MyBase.Attributes("onkeypress") = "return numberOnly(this);"
Dim dec As String = "(this.value);"
If _AllowDisplayDecimal <> DisplayDecimal.None Then
dec = "(this.value, " & _AllowDisplayDecimal & ");"
'dec = "(this.value, '.', " & _AllowDisplayDecimal & ");"
End If
'MyBase.Attributes("onblur") = "this.value = formatCurrency" & dec
'MyBase.Attributes("onblur") = "this.value = formatCurrency2015" & dec
MyBase.Attributes("onblur") = "this.value = formatCurrency2016" & dec
End If
ElseIf (_AllowInputType = InputType.Text AndAlso _isUpperCase = True) Then
MyBase.Attributes("onkeypress") = "var cv = (document.all) ? event.keyCode : event.which; if (cv!='8' && cv!='0' && cv!='27') {this.value+=String.fromCharCode(cv).toUpperCase(); return false;};"
End If
MyBase.OnInit(e)
End Sub
End Class
Good Luck.
|
 |
 |
 |
 |
Date :
2016-06-20 08:57:54 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|