Related with validation [Resolved]

Posted by Amritha444 under ASP.NET on 6/10/2014 | Points: 10 | Views : 580 | Status : [Member] | Replies : 7
Hi All

I have three fields name,address,marital status,spouse ..i want to give validation for all these fields .. problem is validation for spouse should appear only when i checked Ismarried check box .. i used custom validator but its not firing .. can any one give solution for this question

Thanks in Advance
Amritha




Responses

Posted by: Goud.Kv on: 6/10/2014 [Member] [MVP] Gold | Points: 50

Up
0
Down

Resolved
Thanks for your code Amrutha,

Inorder to use Custom validator, you need a RequiredFieldValidator for same control.
Put the RequiredFieldValidator for your textbox(txtspousename) and try.

Hope it will fire your Serverside event.

Thanks & Regards,
Krishna

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 6/10/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi Amritha,

Use the Validation Group.. Kindly post your code to resolve it.

Thanks,

Thanks & Regards,
Krishna

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 6/10/2014 [Member] Starter | Points: 25

Up
0
Down

<asp:TextBox ID="txtspousename" CausesValidation="true" runat="server" Width="260px">
<asp:customvalidator ID="Customvalidator1" EnableClientScript="false" Display="Dynamic" ValidationGroup="v" onservervalidate="Customvalidator1_ServerValidate" forecolor="Red" errormessage="*" controltovalidate="txtspousename" runat="server">


server side

protected void Customvalidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (chkweddingbased.Checked == true)
{
if (txtspousename.Text=="")
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
else
{
args.IsValid = true;
}
}

its not firing when textbox is null..

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gsm_Gsv on: 6/10/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

Use breakpoints and check whether the control is going to args.IsValid = false; or not...
Also, I think the value is becoming true after coming out of the inner if..else...

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 6/10/2014 [Member] Starter | Points: 25

Up
0
Down
Thanks Krishna

Your when i add required field validator its working :D

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 6/10/2014 [Member] Starter | Points: 25

Up
0
Down
Thanks all for your response

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 6/10/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Anytime...

Thanks for posting in DotNetFunda..

Thanks & Regards,
Krishna

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response