Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 3.91 KB

creating-a-numeric-up-down-control-with-a-web-service-backend-cs.md

File metadata and controls

54 lines (35 loc) · 3.91 KB
uid title author description ms.author ms.date ms.assetid msc.legacyurl msc.type
web-forms/overview/ajax-control-toolkit/numericupdown/creating-a-numeric-up-down-control-with-a-web-service-backend-cs
Creating a Numeric Up/Down Control with a Web Service Backend (C#) | Microsoft Docs
wenz
Instead of letting a user type a value into a check box, a numeric up/down control (that exists on Windows and other operating systems) could prove as more c... (C#)
riande
06/02/2008
c99bbc72-d4de-41ed-92a4-9a4632368363
/web-forms/overview/ajax-control-toolkit/numericupdown/creating-a-numeric-up-down-control-with-a-web-service-backend-cs
authoredcontent

Creating a Numeric Up/Down Control with a Web Service Backend (C#)

by Christian Wenz

Download PDF

Instead of letting a user type a value into a check box, a numeric up/down control (that exists on Windows and other operating systems) could prove as more comfortable. By default, the NumericUpDown control always increases or decreases a value by 1, but a web service proves more flexibility.

Overview

Instead of letting a user type a value into a check box, a numeric up/down control (that exists on Windows and other operating systems) could prove as more comfortable. By default, the NumericUpDown control always increases or decreases a value by 1, but a web service proves more flexibility.

Steps

The ASP.NET AJAX Control Toolkit contains the NumericUpDown extender which automatically adds two buttons to a text box: One for increasing its value, one for decreasing it. However the control also supports a web service call (or page method call). Whenever the up or down button is clicked, the JavaScript code connects to the web server and executes a method there. The method signature is the following one:

[!code-csharpMain]

The current argument is the current value in the text box; the tag attribute is additional context data that can be set as a property of the NumericUpDown extender (but is not required).

For this sample, the numeric up/down control shall only allow values that are powers of two: 1, 2, 4, 8, 16, 32, 64, and so on. Therefore, the method executed when the user wants to increase the value must double the old value; the other method must divide value by two. So here is the complete web service:

[!code-aspxMain]

Finally, create a new ASP.NET page. As usual, you need a ScriptManager control, a TextBox control and a NumericUpDownExtender control. For the latter, you have to provide the web service information:

  • ServiceDownMethod name of the down web method or page method
  • ServiceDownPath path to the web service with the down service method; omit if you are using a page method
  • ServiceUpMethod name of the up web method or page method
  • ServiceUpPath path to the web service with the up service method; omit if you are using a page method

Here is the complete markup for the page:

[!code-aspxMain]

If you run the page, notice how the value in the text box always doubles when you click on the upper button, and is halved when you click on the lower button.

Only numbers that are a power of 2 appear

Only numbers that are a power of 2 appear (Click to view full-size image)

[!div class="step-by-step"] Next