Home / AJAX

Ajax Control Toolkit NumericUpDown

RSS
Modified on 2010/04/16 00:52 by Stephen Walther Categorized as Uncategorized
NumericUpDown is an ASP.NET AJAX extender that can be attached to an ASP.NET TextBox control to add "up" and "down" buttons that increment and decrement the value in the TextBox. The increment and decrement can be simple +1/-1 arithmetic, they can cycle through a provided list of values (like the months of the year), or they can call a Web Service to determine the next value. Page authors can also provide custom images to be used instead of the default up/down button graphics.

NumericUpDown Server Reference

The properties in italics are optional.

<ajaxToolkit:NumericUpDownExtender ID="NUD1" runat="server"
    TargetControlID="TextBox1" 
    Width="100"
    RefValues="January;February;March;April"
    TargetButtonDownID="Button1"
    TargetButtonUpID="Button2"
    ServiceDownPath="WebService1.asmx"
    ServiceDownMethod="PrevValue"
    ServiceUpPath="WebService1.asmx"
    ServiceUpMethod="NextValue"
    Tag="1" />

  • TargetControlID - The ID of the TextBox to modify
  • Width - Combined size of the TextBox and Up/Down buttons (min value 25). This property is not used if you provide custom buttons.
  • RefValues - A list of strings separated by semicolons (;) to be used as an enumeration by NumericUpDown
  • Step - Step used for simple numeric incrementing and decrementing. The default value is 1.
  • TargetButtonDownID/TargetButtonUpID - Reference to custom Up/Down buttons.
  • ServiceDownPath/ServiceUpPath - Path to a web service that returns the data used to get the next or previous value. This property should be left null if ServiceUpMethod or ServiceDownMethod refers to a page method. The web service should be decorated with the System.Web.Script.Services.ScriptService attribute.
  • ServiceDownMethod/ServiceUpMethod - Web service method that returns the data used to get the next or previous value, or the name of a method declared on the Page which is decorated with the WebMethodAttribute. The signature of this method must match the following:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public int NextValue(int current, string tag) { ... }

Note you can replace "NextValue" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
  • Tag - Specifies a custom parameter to pass to the Web Service
  • Minimum - The minimum value allowed by the extender. Currently, it does not prevent out of range values from being entered into the textbox even if Minimum or Maximum are specified on the extender, but using the up/down buttons should bring the value into the allowed range when clicked.
  • Maximum - The maximum value allowed by the extender.



NumericUpDown Client Reference

Sys.Extended.UI.NumericUpDownBehavior Class

  • Summary - The NumericUpDownBehavior control is used to add up and down buttons to any textbox.
  • Parameters - Sys.UI.DomElement element

Events

  • currentChanged(handler) - Add or removes an event handler for the currentChanged event.
    • Parameters - A function representing the event handler.

Methods

  • initialize() - Initializes the NumericUpDown control's behavior.
  • dipose() - Disposes the NumericUpDown control's behavior.
  • raiseCurrentChanged(Sys.EventArgs) - Raises the currentChanged event.
    • Parameters - A Sys.EventArgs object representing event arguments for the currentChanged event.
  • readValue() - Reads the value of the associated textbox.
  • setCurrentToTextBox(value) - Sets the value of the associated textbox.

Properties

  • Width - Gets or sets a number that specifies the combined size of the TextBox and Up/Down buttons. Minimum value 25.
    • Remarks - This property is not used if you provide custom buttons.
  • Tag - Gets or sets a string that specifies a custom parameter to pass to the Web Service.
  • TargetButtonUpID - Gets or sets a reference to a custom Up button.
  • TargetButtonDownID - Gets or sets a reference to a custom Down button.
  • ServiceUpPath - Gets or sets the path to a Web service that returns data used to get the next value.
    • Remarks - If the ServiceUpPath property is empty, a PageMethod will be used instead of a Web service.
  • ServiceUpMethod - Gets or sets the name of the method to call on the Web service (or the name of a PageMethod) to get the next value.
  • ServiceDownPath - Gets or sets the path to a Web service that returns data used to get the previous value.
    • Remarks - If the ServiceDownPath property is empty, a PageMethod will be used instead of a Web service.
  • ServiceDownMethod - Gets or sets the name of the method to call on the Web service (or the name of a PageMethod) to get the previous value.
  • RefValues - Gets or sets a string containing a list of strings separated by semicolons (;) to be used as an enumeration.
  • Step - Gets or sets a number that specifies the step value used for simple numeric incrementing and decrementing.
  • Minimum - Gets or sets a number that specifies the minimum value for the NumericUpDown control.
  • Maximum - Gets or sets a number that specifies the maximum value for the NumericUpDown control.

NumericUpDown Known Issues

The display of the default up/down buttons in Safari is such that Safari's "shiny" button style makes the up/down arrows difficult to see. Custom images can be used for complete control over the appearance.