This is a migrated thread and some comments may be shown as answers.

RequiredFieldValidator not working

9 Answers 868 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 30 Jul 2013, 03:19 AM
I had added a RequiredFieldValidator to dropdownlist that make sure user had selected value before insert to db. but the checking is not working that will not prompt error message.

<telerik:RadDropDownList ID="rdl_bu" runat="server" DataSourceID="LDS_BU" DefaultMessage="Please select..."
 DataValueField="BU_ID" DataTextField="BU_name" AutoPostBack="true" >
</telerik:RadDropDownList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="rdl_bu"
         InitialValue="Please Select..." ErrorMessage="Please select a Business Unit."></asp:RequiredFieldValidator>

9 Answers, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 30 Jul 2013, 03:56 AM
Hello,

Please remove the 
InitialValue="Please Select..."

property from your Requiredfieldvalidator.

Thanks,
A2H
0
Edim
Top achievements
Rank 1
answered on 13 Aug 2013, 07:44 AM
Thanks for your answer. i solved the validation problem. when delete the initial value="" property from requiredfield validator
0
Parul
Top achievements
Rank 1
answered on 21 Nov 2013, 08:40 PM
I have the following code for my RadDropDownList ; The Required Field Validator is not being fired. I removed the Initial Value ="0" also. It works fine when I use asp:dropdownlist. Any help will be appreciated.


<telerik:RadDropDownList runat="server" ID="ddlPatients" Width="358px">
            </telerik:RadDropDownList>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="Patient ID is Required"
              ControlToValidate="ddlPatients" runat="server" Text="<img src='../App_Themes/Images/exclamation.png' />"
              SetFocusOnError="True" />
0
Nencho
Telerik team
answered on 26 Nov 2013, 12:35 PM
Hello Parul,

If this is the very same implementation that you are using at your end, the RadDropDownList would be populated, with setting its first item as selected. In this case the validation would pass, because a PatientID is actually selected. If you want to push the user to select an item different from the first one, you could set the InitialValue property of the Required Field Validator and set first item's Text to the InitialValue property, like demonstrated in this video. Other possible implementation would be to set the DefaultMessage property of the RadDropDownList. Thus you would avoid preselecting the first item of the DropDownListItemsCollection, like demonstrated in this video.


Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Parul
Top achievements
Rank 1
answered on 26 Nov 2013, 03:15 PM
I used the property set DefaultMassage and works for me.

Thanks
0
Oscar Emiliano
Top achievements
Rank 1
answered on 04 Jun 2014, 02:58 PM
Hi Nencho, 

I know this post have some time already. I was having the same issue with rad ddl and required field validators and your video help me out. But, what I realized is that there is something odd about required field validator, because, why is it called "InitialValue" if it is considering the Text of the dropdownlist item?

I was always using on my asp.net dropdownlists the Text="- Select -" and the Value="", so my first guess to solve my issue was to put InitialValue="" but it was not working. By checking your video l saw that it was expecting the Text "- Select -" to work properly.

Maybe the property should be called "InitialText" and not "InitialValue" what do you think?, or better: it should be checking the value property from dropdownlist and not the selected text.

Regards



0
Nencho
Telerik team
answered on 09 Jun 2014, 07:57 AM
Hello Oscar,

Indeed, the naming convention could be differently interpreted and sometimes it could cause such misunderstanding. However, I am afraid that the asp:RequiredFieldValidator is not under our jurisdiction and we would have to accept it as it is.

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kiran
Top achievements
Rank 1
answered on 06 Mar 2019, 05:34 PM

Hi,

Required Field Validator works only after the button event has been triggered. Button Submit should not work if the two raddatepickers are empty. It works only after the button submit event has been completed. Please help.

<table style="margin-left: 30px; ">
        <tr>
            <td >
                <asp:Label ID="Label2" runat="server" Text="Date From:" Font-Size="12px"></asp:Label>
            </td>
            <td >
            <telerik:RadDatePicker ID="txtFromDate" Runat="server" Visible="true" Font-Size="12px"   MinDate="2015-01-01">
            </telerik:RadDatePicker>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1"  runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtFromDate" Display="Dynamic" EnableClientScript="false"></asp:RequiredFieldValidator>
            </td>
            <td >
                <asp:Label ID="Label1" runat="server" Text="Date To:" Font-Size="12px"></asp:Label>
            </td>
            <td>
              <telerik:RadDatePicker ID="txtToDate" Runat="server" Visible="true" Font-Size="12px"   MinDate="2015-01-01">
              </telerik:RadDatePicker>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtToDate" Display="Dynamic" EnableClientScript="false"></asp:RequiredFieldValidator>
           </td>
            
            <td>
                <asp:Button runat="server" ID="btnSubmit" Text="SEARCH"  CausesValidation="true"    />
            </td>
        </tr>  
        
     </table>

0
Attila Antal
Telerik team
answered on 11 Mar 2019, 11:28 AM
Hi Kiran,

When the EnableClientScript property is set to false, the control validates after the post back. Setting it to true, the validation will kick in and prevent the post back if values are not present.

<table style="margin-left: 30px;">
    <tr>
        <td>
            <asp:Label ID="Label2" runat="server" Text="Date From:" Font-Size="12px"></asp:Label>
        </td>
        <td>
            <telerik:RadDatePicker ID="txtFromDate" runat="server" Visible="true" Font-Size="12px" MinDate="2015-01-01">
            </telerik:RadDatePicker>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtFromDate" Display="Dynamic" EnableClientScript="true"></asp:RequiredFieldValidator>
        </td>
        <td>
            <asp:Label ID="Label1" runat="server" Text="Date To:" Font-Size="12px"></asp:Label>
        </td>
        <td>
            <telerik:RadDatePicker ID="txtToDate" runat="server" Visible="true" Font-Size="12px" MinDate="2015-01-01">
            </telerik:RadDatePicker>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtToDate" Display="Dynamic" EnableClientScript="true"></asp:RequiredFieldValidator>
        </td>
 
        <td>
            <asp:Button runat="server" ID="btnSubmit" Text="SEARCH" CausesValidation="true" />
        </td>
    </tr>
</table>


Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownList
Asked by
Joe
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
Edim
Top achievements
Rank 1
Parul
Top achievements
Rank 1
Nencho
Telerik team
Oscar Emiliano
Top achievements
Rank 1
Kiran
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or