Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
XML
Hi,
     I have 2 text boxes and 3 drop down lists as mandatory fields. I am using javascript and asp .net validator for validation. When I click on the submit button all the 5 validator should work. But in my code only one validator is working.
My javascript code is:
var Page_IsValid = false;
Page_IsValid =Page_ClientValidate('valgrpCode');
Page_IsValid = Page_ClientValidate('valgrpDescription');
 Page_IsValid = Page_ClientValidate('valgrpCategory');
and my asp code is:
<asp:RequiredFieldValidator ID="reqCode" runat="server" ErrorMessage="*" ControlToValidate="txtCode" ValidationGroup="valgrpCode" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="reqDescription" runat="server" ErrorMessage="*" ControlToValidate="txtDescription" ValidationGroup="valgrpDescription" ForeColor="Red"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator ID="reqCategory" runat="server" ErrorMessage="*" ControlToValidate="txtCategory" ValidationGroup="valgrpCategory" ForeColor="Red"></asp:RequiredFieldValidator>

and also here i am showing "*" as mandatory message.  But I need to change the color of label as mandatory message. I have added labels for each text boxes and drop down lists.
Posted

1 solution

Hello,

You have to use only one validation group for each validation control.

ASP.NET
<asp:requiredfieldvalidator id="reqCode" runat="server" errormessage="*" controltovalidate="txtCode" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>
<asp:requiredfieldvalidator id="reqDescription" runat="server" errormessage="*" controltovalidate="txtDescription" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>
 
<asp:requiredfieldvalidator id="reqCategory" runat="server" errormessage="*" controltovalidate="txtCategory" validationgroup="valgrpCode" forecolor="Red" xmlns:asp="#unknown"></asp:requiredfieldvalidator>
 
Share this answer
 
Comments
My Doubt 16-May-14 2:20am    
Thanks , But the problem is that I can't use validation in next page.
Sunasara Imdadhusen 16-May-14 2:23am    
Sorry!! can you explain what you want to say " But the problem is that I can't use validation in next page"
My Doubt 16-May-14 2:39am    
Hi Sunasara,
I have 2 pages in my project, but I have placed mandatory fields in first page. So there is no issue. But if I have mandatory field in next page I can't see * , so the user think that there is some error. But if the * appears on clearing each mandatory fields there will not have any confusion.
Sunasara Imdadhusen 16-May-14 5:07am    
not clear. still confusion
My Doubt 16-May-14 6:13am    
ooh leave it I will post my requirement later

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900