skip to Main Content

The problem I’m having is when a user skips over cycle time, even with the required field validator in place it allows to to still submit and crash the page. I tried setting an initial value but that didn’t work.

<div class="col-lg-4" style="text-align: left;">
    <label for="txtCycle_Time">Cycle Time (format mm:ss) :</label>
    <asp:TextBox ID="txtCycle_Time" MaxLength="5" CssClass="form-control" runat="server"></asp:TextBox>
    <ajaxToolkit:MaskedEditExtender ID="txtCycle_Time_MaskedEditExtender" AutoComplete="true" MaskType="Time" AcceptAMPM="false" runat="server" MessageValidatorTip="true" TargetControlID="txtCycle_Time" Mask="99:99" ClearMaskOnLostFocus="false" />
    <asp:RequiredFieldValidator ID="txtCycle_Time_RequiredFieldValidator" runat="server" InitialValue="00:00" Text="Please Enter Cycle Time" ControlToValidate="txtCycle_Time" ValidationGroup="Input" Font-Italic="True" ForeColor="Red" />
</div>
Dim Cycle_Time_Sec As Integer = 0
Dim My_Time As String = ""
My_Time = txtCycle_Time.Text
Dim Min As String = My_Time.Substring(0, 2)
Dim Sec As String = My_Time.Substring(3, 2)
Cycle_Time_Sec = Min * 60 + Sec

2

Answers


  1. Chosen as BEST ANSWER

    Wrote this to fix the issue, now form works as intended.

     If (txtCycle_Time.Text.Trim = "__:__" Or txtCycle_Time.Text.Trim = "__:__ AM" 
          Or txtCycle_Time.Text.Trim = "__:__ PM") Then ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Cycle_Time_Error", "Cycle_Time_Error();", True)
                Exit Sub
            End If
    

  2. You could try a server side validation on postback:

    Dim Cycle_Time_Sec As Integer = 0
    Dim My_Time As String = ""
    
    //Validation here
    If txtCycle_Time.Text is null Then return "Please type time value!"
    
    My_Time = txtCycle_Time.Text
    Dim Min As String = My_Time.Substring(0, 2)
    Dim Sec As String = My_Time.Substring(3, 2)
    Cycle_Time_Sec = Min * 60 + Sec
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search