Search code examples
asp.netfieldvalidationrequired

ASP.NET Required Field Validator not working


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?


Solution

  • 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>