Numeric TextBox (ASP.Net / HTML Input)

<
script language="javascript">

function KeyCheck(e)

{

var KeyID = (window.event) ? event.keyCode : e.which;

if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||

(KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))

{

return false;

}

return true;

}

</
script>
HTML Text Box

<

input type="text" ID="txt_TextBox" onkeypress="return KeyCheck(event);" runat="server" style="width: 28px" />

ASP.Net TextBox

<asp:TextBox ID="txt_ASPTextBox" runat="server" ></asp:TextBox>

Code Behind for Asp.Net TextBox

txt_ASPTextBox.Attributes.Add("onkeypress","return KeyCheck(event);");

Comments

Anonymous said…
Thanks. Found this topic very useful but still having problems while setting some attributes in Page_Load event for user control e.g. NumericTextBox1.Attribute.Add("CssClass", "form"). Plz need ur help.
Rizwan Shah said…
To Apply a class attribute use simple "class" instead of "CssClass" hope this will help you.

Popular posts from this blog

Visual Studio 2008 simplifies JavaScript debugging

Restrict Web Page access based on MAC / IP

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies