Allow only numeric textbox demo

Source: Internet
Author: User

There is a need to enter numbers in the GridView in batches!

So I thought about encapsulating a TextBox

The code is as follows:

public class Numbertext:textbox
{
Private Const String smb_number_script_id = "{c4f7dcfd-8f9b-4fe8-8bd1-4a8a1f145c0c}";
Private Const string Smb_number_script_only_hook = "return Numbereditor_keypress_handle (This)";
Private Const string smb_number_script_only_script = "<script language=\" javascript\ ">\n" +
"Function Numbereditor_keypress_handle (ctrl) \n{{" +
"if (Event.keycode =) \ n return true;\n" +
"If" (event.keycode<48 | | event.keycode>57) \ n "+
"Return false;\n else \ return true;\n}}" +
"</script>";
private void Renderjavscript ()
{
if (! Page.ClientScript.IsClientScriptBlockRegistered (smb_number_script_id))
{
Page.ClientScript.RegisterClientScriptBlock (Page.gettype (), smb_number_script_id, String. Format (Smb_number_script_only_script, base.id));
}
}
protected override void AddAttributesToRender (HtmlTextWriter writer)
{
Base. AddAttributesToRender (writer);
Writer. AddAttribute ("OnKeyPress", Smb_number_script_only_hook);
}
protected override void OnPreRender (EventArgs e)
{
Base. OnPreRender (e);
Renderjavscript ();
}
Public Numbertext ()
: Base ()
{ }
}

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.