Could any one tell me why this is not working, I think I have the correct coding here.
Located in the App_Code folder
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomControls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[DefaultProperty("Text")]
[ToolboxData("<{0}:NumbericTextBox runat=server></{0}:NumbericTextBox>")]
//--public class NumbericTextBox : TextBox //- When This used it does not call the javascript
public class NumbericTextBox : CompositeControl
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public override string ID
set
base.ID = value;
}
public override Unit Height
get
return base.Height;
base.Height = value;
public override Unit Width
return base.Width;
base.Width = value;
#region OnPreRender
/// <summary>
/// The OnPreRender event. Use this event to raise any events that need to be fired before our controls are rendered.
/// </summary>
protected override void OnPreRender(EventArgs e)
base.OnPreRender(e);
string resourceName = "CustomControls.validatenumeric.js";
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(CustomControls.NumbericTextBox), resourceName);
#endregion OnPreRender
protected override void CreateChildControls()
this.Controls.Clear();
TextBox txtBox1 = new TextBox();
//- Numeric TextBox
txtBox1.ID = this.ID;
txtBox1.Width = this.Width;
txtBox1.Height = this.Height;
txtBox1.ToolTip = "Numeric Value Only";
txtBox1.Attributes.Add("onkeypress", "return IsNumbericValue(event)");
txtBox1.Style.Add("text-align", "right");
//- Add the control to the environment
this.Controls.Add(txtBox1);
function IsNumbericValue(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
else {
// If the number field already has . then don't allow to enter . again.
if (evt.target.value.search(/\./) > -1 && charCode == 46) {
return true;
<%@ Register Namespace="CustomControls" Assembly="__code" tagprefix="cc1" %>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />