如何检查TextBox值ASP.NET的倍数

时间:2018-09-25 09:59:51

标签: asp.net vb.net

这是我的ASP.NET页面:

                    <div id="dvtgl1" style="display: none">1. 
                        <asp:TextBox  ID="TxtTglCuti1"   runat="server" MaxLength="1"  style="width: 140px; height: 35px; padding: 12px 10px;  box-sizing: border-box; border: 1px solid Silver; border-radius: 4px;" ValidationGroup="MKE"></asp:TextBox><br /><br /></div>                            
                    <div id="dvtgl2" style="display: none">2. 
                        <asp:TextBox  ID="TxtTglCuti2"   runat="server" MaxLength="1"  style="width: 140px; height: 35px; padding: 12px 10px;  box-sizing: border-box; border: 1px solid Silver; border-radius: 4px; " ValidationGroup="MKE"></asp:TextBox><br /><br /></div>

这是我的jQuery脚本:

$(function(){

            $("#<%= TxtTglCuti1.ClientID %>").datepicker({
                //dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                showButtonPanel: true,
                minDate: dateToday,
                beforeShowDay: DisableMonday

            });
            $("#<%= TxtTglCuti2.ClientID %>").datepicker({
               // dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                showButtonPanel: true,
                minDate: dateToday, beforeShowDay: DisableMonday

            });

这是我的VB.NET课:

If (TxtTglCuti1.Text = "") And (TxtTglCuti2.Text = "") And (TxtTglCuti3.Text = "") And (TxtTglCuti4.Text = "") And (TxtTglCuti5.Text = "") And (TxtTglCuti6.Text = "") And (TxtTglCuti7.Text = "") And (TxtTglCuti8.Text = "") And (TxtTglCuti9.Text = "") And (TxtTglCuti10.Text = "") And (TxtTglCuti11.Text = "") And (TxtTglCuti12.Text = "") Then
    Response.Write("<script>alert('Data tidak boleh kosong')</script>")

与其构建代码块来检查每个TextBox中包含所有文本框的日期DateTimePicker和jQuery的代码,我构建它是将值分配给这样的数组:

    txt_tgl_cuti(0) = TxtTglCuti1.Text
    txt_tgl_cuti(1) = TxtTglCuti2.Text

问题是,它仅适用于少量记录。

我应该如何动态检查它?我有12条文本框记录,我的目标是建立一个防止用户在TextBox

中输入重复日期值的功能

1 个答案:

答案 0 :(得分:0)

下面是您可以检查所有文本框值为空的一种简单方法,

.ASPX

<asp:PlaceHolder ID="plhDates" runat="server">
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
     <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</asp:PlaceHolder>
<asp:Button ID="btnSubmit" Text="text" runat="server" OnClick="btnSubmit_Click" />

.VB

Protected Function MySub() As Boolean
        For Each ctl As Control In plhDates.Controls
            If TypeOf ctl Is TextBox Then
                If (CType(ctl, TextBox).Text = "") Then
                    Return True
                End If
            End If
        Next
        Return False
End Function

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs)
    Dim isContainBlankValue As Boolean = MySub() //return true if any of the textbox have blank value
End Sub