9

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?

1
  • 2
    Need to put ValidationGroup to txtTimeSlotGroupName :) Commented Apr 25, 2013 at 5:38

10 Answers 10

23

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> 
Sign up to request clarification or add additional context in comments.

Comments

9

Remove InitialValue="0" from the RequiredFieldValidator tag, it is not required when you are validating the textbox.

Comments

7

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

Comments

3

If two objects have the same id the required field validator Does not work.

3 Comments

Can you clarify? "Objects" do not have an "id" - do you mean names for variables? If so, from which context? Or, perhaps you mean the "id" attribute of an element? If so, which elements? Do you mean any elements on the page with the same id will break validation? I doubt that, but that's the closest I can come to interpreting this answer. Thank you in advance for any additional detail you can provide!!
Late to the party but CHEGNI means any element on the page. A text box, a required field validator, a buton, a custom validator, ANYTHING. Any two elements that have id="idname". if any two have the same ID then some things can go wrong, especially in javascript.
@CHEGENI is right? any solution for this after 6 years
1

You just add ValidationGroup="TimeSlot" in textbox

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

Comments

1

I had this same issue... but none of the above answers were the fix for me...

My problem was that I was missing the Page.isValid in my button press method. Below is my button code and the method called by the button.

Button:

<asp:Button ID="btnBtmSave" runat="server" Text="Save" OnClick="btnSave_Click" BtnGroup="save" TabIndex="18" /> 

Button method:

protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { //Logic goes here } } 

Comments

0

make the same Validation Group Of all your text and Add button and Validation

 ValidationGroup="AAA" 

and add the code to your save button:

 If (Page.IsValid) Then YOURSQL.Insert() 'or ur code here' End If 

Comments

0

In my case, For button, I was using both client side validation i.e onClientClick="return validate()", and ASP.NET Validation i.e Reguired field Validation (ValidationGroup). Hence the Required field validators were not firing.

Comments

0

firstly go to config file and add code after the</system.we>

 <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/> </appSettings> 

Comments

0

In my case it didn't work because the HTML of the container was modified by javascript (jQuery actually).

Some answers mention the use of the ValidationGroup attribute, but I don't think that is relevant to the original question, because it is not a required attribute and it only restricts the buttons that perform validation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.