功能:
与TextBox控件联合用于增加或减少TextBox中的Value值。
属性:
TargetControlID:该控件的目标作用控件。
Width:该控件加上目标TextBox控件的宽度,要是不设定将看不到TextBox控件。
RefValues:该控件中使用的一个字符串列,用于在TextBox中递增递减。
ServiceUpPath:调用增加值的web方法时的路径。
ServiceDownPath:调用减少值的web方法时的路径。
ServiceUpMethod:调用增加值的web方法。
ServiceDownMethod:调用减少值的web方法。
TargetButtonUpID:自定义的增加值的控件按钮。
TargetButtonDownID:自定义的减少值的控件按钮。
实例代码:
运行结果:
与TextBox控件联合用于增加或减少TextBox中的Value值。
属性:
TargetControlID:该控件的目标作用控件。
Width:该控件加上目标TextBox控件的宽度,要是不设定将看不到TextBox控件。
RefValues:该控件中使用的一个字符串列,用于在TextBox中递增递减。
ServiceUpPath:调用增加值的web方法时的路径。
ServiceDownPath:调用减少值的web方法时的路径。
ServiceUpMethod:调用增加值的web方法。
ServiceDownMethod:调用减少值的web方法。
TargetButtonUpID:自定义的增加值的控件按钮。
TargetButtonDownID:自定义的减少值的控件按钮。
实例代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center><h1>NumericUpDown控件的使用</h1></center>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Enter a numeric value and use the up and down buttons to <br />increment/decrement(min:1 and max:7)
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Choose your favorite month
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
Let the web service pick a random number between 0 and <br /> 1000 that is
higher/lower than the displayed value
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<br />
Use the arrow images to increment/decrement the value
<asp:TextBox ID="TextBox4" runat="server" Height="15px"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender4" TargetControlID="TextBox4" Width="150" TargetButtonUpID="ImageButtonUp" TargetButtonDownID="ImageButtonDown" runat="server">
</ajaxToolkit:NumericUpDownExtender>
<asp:ImageButton ID="ImageButtonDown" runat="server" Width="15px" Height="15px" ImageUrl="~/Images/ArrowDown01.gif" />
<asp:ImageButton ID="ImageButtonUp" runat="server" Width="15px" Height="15px" ImageUrl="~/Images/ArrowUp01.gif" /> <br />
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" TargetControlID="TextBox1" Width="150" Minimum=1 Maximum=7 runat="server">
</ajaxToolkit:NumericUpDownExtender>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender2" TargetControlID="TextBox2" Width="150" RefValues="January;February;March;April;May;June;July;August;September;October;November;December" runat="server">
</ajaxToolkit:NumericUpDownExtender>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender3" TargetControlID="TextBox3" Width="150" ServiceUpPath="WebServiceNumbericUpDown.asmx" ServiceUpMethod="PreNumber" ServiceDownPath="WebServiceNumbericUpDown.asmx" ServiceDownMethod="NextNumber" Tag="3" runat="server">
</ajaxToolkit:NumericUpDownExtender>
</form>
</body>
</html>
WebService代码如下:<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center><h1>NumericUpDown控件的使用</h1></center>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Enter a numeric value and use the up and down buttons to <br />increment/decrement(min:1 and max:7)
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Choose your favorite month
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
Let the web service pick a random number between 0 and <br /> 1000 that is
higher/lower than the displayed value
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<br />
Use the arrow images to increment/decrement the value
<asp:TextBox ID="TextBox4" runat="server" Height="15px"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender4" TargetControlID="TextBox4" Width="150" TargetButtonUpID="ImageButtonUp" TargetButtonDownID="ImageButtonDown" runat="server">
</ajaxToolkit:NumericUpDownExtender>
<asp:ImageButton ID="ImageButtonDown" runat="server" Width="15px" Height="15px" ImageUrl="~/Images/ArrowDown01.gif" />
<asp:ImageButton ID="ImageButtonUp" runat="server" Width="15px" Height="15px" ImageUrl="~/Images/ArrowUp01.gif" /> <br />
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" TargetControlID="TextBox1" Width="150" Minimum=1 Maximum=7 runat="server">
</ajaxToolkit:NumericUpDownExtender>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender2" TargetControlID="TextBox2" Width="150" RefValues="January;February;March;April;May;June;July;August;September;October;November;December" runat="server">
</ajaxToolkit:NumericUpDownExtender>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender3" TargetControlID="TextBox3" Width="150" ServiceUpPath="WebServiceNumbericUpDown.asmx" ServiceUpMethod="PreNumber" ServiceDownPath="WebServiceNumbericUpDown.asmx" ServiceDownMethod="NextNumber" Tag="3" runat="server">
</ajaxToolkit:NumericUpDownExtender>
</form>
</body>
</html>
public class WebServiceNumbericUpDown : System.Web.Services.WebService {
public WebServiceNumbericUpDown () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public int NextNumber(int current, string tag)
{
Random r1 = new Random();
return r1.Next(Math.Min(Math.Max(0,current), 1000), 1001);
}
[WebMethod]
public int PreNumber(int current, string tag)
{
Random r2 = new Random();
return r2.Next(0, Math.Min(Math.Max(0,current), 1000));
}
}
public WebServiceNumbericUpDown () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public int NextNumber(int current, string tag)
{
Random r1 = new Random();
return r1.Next(Math.Min(Math.Max(0,current), 1000), 1001);
}
[WebMethod]
public int PreNumber(int current, string tag)
{
Random r2 = new Random();
return r2.Next(0, Math.Min(Math.Max(0,current), 1000));
}
}
运行结果: