views:

68

answers:

3

I would like to make one numeric-only textbox. I'd like to then add that same to the control toolbox within Visual Studio 2008

I've already built the function to allow only numeric.

How can I make it available in the toolbox?

+1  A: 
this is how you can create numeric textbox

public class NumericTextBox : TextBox
{
    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
        {
            e.Handled = true;
        }
        base.OnKeyPress(e);
    }
}
Serkan Hekimoglu
sorry, i knew this.. hiw can i make it as a control.
pvaju896
ont textbox that allows only numeric the same control i can use it for any of my projects..
pvaju896
make this class library, and then right click to project, add new item, add new icon file for your class, rename it NumericTB. And go to toolbox, right click, choose items, and choose your numeric textbox dll. and you call it like [System.ComponentModel.DefaultEvent("KeyPress"), DefaultProperty("Text"), System.Drawing.ToolboxBitmap(@"../../NumericTB.ico")]
Serkan Hekimoglu
Ouch. You're missing a whole lot of things. Decimal point, tousands separator, minus sign are only three of them. Copy/paste will still allow you to enter non-numeric characters. You can enter any decimal digit you like (regardless of script) – I doubt anything will reliably parse that. There's quite a lot of issues here and designing sucha control properly takes more than three lines of code.
Joey
As well, the poster indicated dotnetnuke, which is web. This wouldn't work in that environment.
Robaticus
A: 

Please Check the Link

http://msdn.microsoft.com/en-us/library/yhzc935f.aspx

This will help you to Create Custom Control and How to use the control in web form

you can inherit the WebControl Class and add your numeric only logic in your control

Ramakrishnan
A: 

Don't reinvent the wheel. Download this:
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/NumericUpDown/NumericUpDown.aspx

Bill