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?
Even I was facing the same issue. Kindly check if any javascript are present on your page. Irrespective of above make use of Page.Validate()
method and if(Page.IsValid)
in your code. This will automatically force your validation controls and issue will be solved
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>
If two objects have the same id the required field validator Does not work.
Remove InitialValue="0" from the RequiredFieldValidator tag, it is not required when you are validating the textbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With