AJAX ControlToolkit学习日志-NumericUpDownExtender(18)

         NumericUpDownExtender控件与TextBox控件联合用于增加或减少TextBox中的Value值。

下面看一个示例:

1)在VS2005中新建一个ASP.NET AJAX-Enabled Web Project项目工程,命名为NumericUpDownExtender1。

2)在页面上拖放4个TextBox控件和4个NumericUpDownExtender控件,并进行一些设置。

代码如下:

 1 None.gif             Enter a numeric value and use 
 2 None.gif             < br  />
 3 None.gif            the up and down buttons to increment/decrement  &nbsp;   &nbsp;   &nbsp; < asp:TextBox  ID ="TextBox1"
 4 None.gif                runat ="server" ></ asp:TextBox >
 5 None.gif             < br  />
 6 None.gif             < br  />
 7 None.gif            Choose your favorite month  &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
 8 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
 9 None.gif             < asp:TextBox  ID ="TextBox2"  runat ="server" ></ asp:TextBox >< br  />
10 None.gif             < br  />
11 None.gif            Let the web service pick a random number
12 None.gif             < br  />
13 None.gif            between 0 and 1000 that is higher/lower
14 None.gif             < br  />
15 None.gif            than the displayed value  &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
16 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
17 None.gif             &nbsp;
18 None.gif             < asp:TextBox  ID ="TextBox3"  runat ="server" ></ asp:TextBox >< br  />
19 None.gif             < br  />
20 None.gif            Use the arrow images to increment/decrement  &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
21 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
22 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;&nbsp;
23 None.gif             < br  />
24 None.gif            the value  &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
25 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
26 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
27 None.gif             < asp:TextBox  ID ="TextBox4"  runat ="server"  Height ="1px" ></ asp:TextBox >
28 None.gif             < asp:ImageButton  ID ="ImageButton2"  runat ="server"  Width ="15px"  Height ="15px"  ImageUrl ="~/up.gif"   />
29 None.gif             &nbsp;
30 None.gif             < br  />
31 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
32 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
33 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
34 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
35 None.gif             &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;   &nbsp;
36 None.gif             < asp:ImageButton  ID ="ImageButton1"  runat ="server"  Width ="15px"  Height ="15px"  ImageUrl ="~/down.gif"   />< br  />
37 None.gif             < cc1:NumericUpDownExtender  ID ="NumericUpDownExtender1"  TargetControlID ="TextBox1"  Width ="150"    runat ="server" >
38 None.gif             </ cc1:NumericUpDownExtender >
39 None.gif             < cc1:NumericUpDownExtender  ID ="NumericUpDownExtender2"  TargetControlID ="TextBox2"  Width ="150"  RefValues ="January;February;March;April;May;June;July;August;September;October;November;December"  runat ="server" >
40 None.gif             </ cc1:NumericUpDownExtender >
41 None.gif             < cc1:NumericUpDownExtender  ID ="NumericUpDownExtender3"  TargetControlID ="TextBox3"  Width ="150"  ServiceUpPath ="WebService1.asmx"  ServiceUpMethod ="NextNumber"  ServiceDownPath ="WebService1.asmx"  ServiceDownMethod ="PreNumber"  runat ="server" >
42 None.gif             </ cc1:NumericUpDownExtender >
43 None.gif             < cc1:NumericUpDownExtender  ID ="NumericUpDownExtender4"  TargetControlID ="TextBox4"  Width ="150"  TargetButtonUpID ="ImageButton2"  TargetButtonDownID ="ImageButton1"  runat ="server" >
44 None.gif             </ cc1:NumericUpDownExtender >

属性说明:

      TargetControlID:该控件的目标作用控件。
      Width:该控件加上目标TextBox控件的宽度,要是不设定将看不到TextBox控件。
      RefValues:该控件中使用的一个字符串列,用于在TextBox中递增递减。
      ServiceUpPath:调用增加值的web方法时的路径。
      ServiceDownPath:调用减少值的web方法时的路径。
      ServiceUpMethod:调用增加值的web方法。
      ServiceDownMethod:调用减少值的web方法。
      TargetButtonUpID:自定义的增加值的控件按钮。
      TargetButtonDownID:自定义的减少值的控件按钮。

3)在工程中添加一个web服务,在类名前加上

None.gif [System.Web.Script.Services.ScriptService()]

方法代码如下:
 1 None.gif         [WebMethod]
 2 None.gif         public   int  NextNumber( int  current,  string  tag)
 3 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 4InBlock.gif            Random r1 = new Random();
 5InBlock.gif            return r1.Next(Math.Min(Math.Max(0,current), 1000), 1001);
 6ExpandedBlockEnd.gif        }

 7 None.gif
 8 None.gif        [WebMethod]
 9 None.gif         public   int  PreNumber( int  current,  string  tag)
10 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
11InBlock.gif            Random r2 = new Random();
12InBlock.gif            return r2.Next(0, Math.Min(Math.Max(0,current), 1000));
13ExpandedBlockEnd.gif        }

4)按下CTRL+F5,在浏览器里浏览效果。

效果图如下:

转载于:https://www.cnblogs.com/qc1984326/archive/2007/03/20/681909.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值