日付時刻、日付、時刻、数値の各コントロールには入力範囲を指定することが可能です。範囲外の値が入力されたときにどのように値を制御するかを設定することもできます。
using GrapeCity.Web.Input.Core; using System; public partial class Validate_InvalidRange : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { // 範囲外値の制御方法を設定します。 GcDateTime1.MaxMinBehavior = (MaxMinBehavior)DropDownList1.SelectedIndex; GcDate1.MaxMinBehavior = (MaxMinBehavior)DropDownList1.SelectedIndex; GcTime1.MaxMinBehavior = (MaxMinBehavior)DropDownList1.SelectedIndex; GcNumber1.MaxMinBehavior = (MaxMinBehavior)DropDownList1.SelectedIndex; // 入力中に検証を行うかどうかを設定します。 GcDateTime1.AdjustValueOnFocus = CheckBox1.Checked; GcDate1.AdjustValueOnFocus = CheckBox1.Checked; GcTime1.AdjustValueOnFocus = CheckBox1.Checked; GcNumber1.AdjustValueOnFocus = CheckBox1.Checked; } }
Partial Class Validate_InvalidRange Inherits System.Web.UI.Page Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click ' 範囲外値の制御方法を設定します。 GcDateTime1.MaxMinBehavior = DropDownList1.SelectedIndex GcDate1.MaxMinBehavior = DropDownList1.SelectedIndex GcTime1.MaxMinBehavior = DropDownList1.SelectedIndex GcNumber1.MaxMinBehavior = DropDownList1.SelectedIndex ' 入力中に検証を行うかどうかを設定します。 GcDateTime1.AdjustValueOnFocus = CheckBox1.Checked GcDate1.AdjustValueOnFocus = CheckBox1.Checked GcTime1.AdjustValueOnFocus = CheckBox1.Checked GcNumber1.AdjustValueOnFocus = CheckBox1.Checked End Sub End Class
<%@ page title="" language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="Validate_InvalidRange, App_Web_rrwzlsxq" stylesheettheme="SkinFile" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMDate" tagprefix="im_date" %> <%@ Register assembly="GrapeCity.Web.Input.v100, Version=10.0.4006.2012, Culture=neutral, PublicKeyToken=c3bd7c1dccef5128" namespace="GrapeCity.Web.Input.IMNumber" tagprefix="im_number" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <script type="text/javascript"> // 範囲外値の制御方法を設定します。 function MaxMinBehavior(maxminbehavior) { if (!document.getElementById("isClient").checked) return; FindIMControl("<% =GcDateTime1.ClientID %>").SetMaxMinBehavior(maxminbehavior); FindIMControl("<% =GcDate1.ClientID %>").SetMaxMinBehavior(maxminbehavior); FindIMControl("<% =GcTime1.ClientID %>").SetMaxMinBehavior(maxminbehavior); FindIMControl("<% =GcNumber1.ClientID %>").SetMaxMinBehavior(maxminbehavior); } // 入力中の検証方法を設定します。 function ValidateOnFocus(obj) { if (!document.getElementById("isClient").checked) return; FindIMControl("<% =GcDateTime1.ClientID %>").SetAdjustValueOnFocus(obj.checked); FindIMControl("<% =GcDate1.ClientID %>").SetAdjustValueOnFocus(obj.checked); FindIMControl("<% =GcTime1.ClientID %>").SetAdjustValueOnFocus(obj.checked); FindIMControl("<% =GcNumber1.ClientID %>").SetAdjustValueOnFocus(obj.checked); } </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div class="sample"> <table> <tr> <th colspan="3">入力確認</th> </tr> <tr> <td class="controlsTd">日付時刻:</td> <td> <im_date:GcDateTime ID="GcDateTime1" runat="server" HasLoadFromXml="True" Width="200px" MaxDate="2015/12/31 23:59:59" MinDate="2015/01/01 00:00:00"> <helpvalue value="2015/01/01 00:00:00" ></helpvalue> </im_date:GcDateTime> </td> <td align="left" class="controlsTd">(2015/1/1 00:00:00~2015/12/31 23:59:59)</td> </tr> <tr> <td class="controlsTd">日付:</td> <td> <im_date:GcDate ID="GcDate1" runat="server" HasLoadFromXml="True" Width="200px" MaxValue="2015/03/31 23:59:59" MinValue="2015/03/01 00:00:00"> <helpvalue value="2015/03/01 00:00:00" ></helpvalue> </im_date:GcDate> </td> <td align="left" class="controlsTd">(2015/3/1~2015/3/31)</td> </tr> <tr> <td class="controlsTd">時刻:</td> <td> <im_date:GcTime ID="GcTime1" runat="server" HasLoadFromXml="True" Width="200px" MaxValue="18:00:00" MinValue="12:00:00"> <helpvalue value="1900/01/01 12:00:00"></helpvalue> </im_date:GcTime> </td> <td align="left" class="controlsTd">(12:00:00~18:00:00)</td> </tr> <tr> <td class="controlsTd">数値:</td> <td> <im_number:GcNumber ID="GcNumber1" runat="server" HasLoadFromXml="True" Width="200px" MaxValue="100" MinValue="-100"> <DropDown DropDownType="NumericPad" /> <helpvalue value = "-100" ispositive="False" ></helpvalue></im_number:GcNumber> </td> <td align="left" class="controlsTd">(-100~100)</td> </tr> </table> </div> <label style="font-size:80%;"><input type="checkbox" id="isClient" checked="checked" /> クライアント側の設定を有効にする</label> <table class="inputTable"> <tr> <th class="inputTh">範囲外値の制御方法</th> <td class="inputTd"> <asp:DropDownList ID="DropDownList1" runat="server" onchange="MaxMinBehavior(this.value);"> <asp:ListItem Value="adjusttomaxmin">最大値か最小値の近い方に設定</asp:ListItem> <asp:ListItem Value="clear">値を削除</asp:ListItem> <asp:ListItem Value="restore" Selected="True">変更前の値に戻す</asp:ListItem> <asp:ListItem Value="cancelinput">最後の入力をキャンセルする</asp:ListItem> <asp:ListItem Value="keep">最後に入力された現在値を保持</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <th class="inputTh">入力中の検証</th> <td class="inputTd"> <asp:CheckBox ID="CheckBox1" runat="server" Text="入力中(フォーカス移動前)に検証を行う" onclick="ValidateOnFocus(this);" /> </td> </tr> </table> <center> <asp:Button ID="Button1" runat="server" Text="サーバー側で設定" CssClass="button_nowidth" onclick="Button1_Click" /> </center> </asp:Content>