ASP.NET Required Field Validator not working

MusicLovingIndianGirl picture MusicLovingIndianGirl · Apr 25, 2013 · Viewed 61.4k times · Source

Hi all I need a required field validator for my textbox..This is my textbox..

<asp:TextBox ID="txtTimeSlotGroupName" runat="server" AutoPostBack="false" 
     ClientIDMode="Static"></asp:TextBox>  
<font color="red">*</font>  
<asp:RequiredFieldValidator ID="RequiredFieldValidator_txtTimeSlotGroupName"
     runat="server" ControlToValidate="txtTimeSlotGroupName" Display="None"
     ErrorMessage="Timeslot Group Required!" ForeColor="Red" InitialValue="0"
     ValidationGroup="TimeSlot"></asp:RequiredFieldValidator>

My button:

<asp:Button ID="btnAddTimeSlots" Text="Add Timeslots" CssClass="button" 
     runat="server" OnClick="btnAddTimeslots_Click" ValidationGroup="TimeSlot" 
     OnClientClick="javascript:shouldsubmit=true;"/>

I am not getting the error message. Any solutions?

Answer

Amit Singh picture Amit Singh · Apr 25, 2013

You have to define the Validation Group Of your Textbox too....to make it work

   <asp:TextBox ID="txtTimeSlotGroupName" runat="server" 
        AutoPostBack="false" ValidationGroup="TimeSlot" ClientIDMode="Static"></asp:TextBox>