enable validation according to condition..

Posted by Gopal_nivas under ASP.NET on 8/9/2010 | Views : 2752 | Status : [Member] | Replies : 3
hi..

i have 2 radio buttons.. and two textboxes and 2 required field validator controls

if i selects first radio button and click the submit button means it validates only the textbox1 but not textbox2..

how to do this..

need ur suggestions..
explain with examples

regards
gopal.s




Responses

Posted by: Shankul2784 on: 8/9/2010 [Member] Bronze

Up
0
Down

Hi,

For this you have to use the custom validator, in which you have to write the javascript to validate the requirement.


Thanks & Regards,

Shailesh

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

Posted by: Gopal_nivas on: 8/9/2010 [Member] Starter

Up
0
Down
hi shan

plz expalin briefly with example

regards

gopal.s

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

Posted by: Shankul2784 on: 8/9/2010 [Member] Bronze

Up
0
Down

Hi,

First you have to add the custom validator

<asp:CustomValidator ID="CV1" runat="Server" ClientValidationFunction="JSValidate"
ControlToValidate="firsttextboxname" ValidateEmptyText="True" ErrorMessage="Validation Failed"></asp:CustomValidator>

then add the following javascript -

<script language="javascript" type="text/javascript">
function JSValidate(source, args)
{
var firsttextbox= document.getElementById('<%=firsttextboxl.ClientID %>');

var secondtextboxl= document.getElementById('<%=secondtextboxl.ClientID %>');

var firstrbo= document.getElementById('<%=firstrbo.ClientID %>');

var secondrbo= document.getElementById('<%=secondrbo.ClientID %>');

if (firstrbo.checked == true)
{
if(firsttextbox.value == '')
{

alert('message');
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

//write same for second one
</script>

i hope this will help you.

Thanks & Regards,

Shailesh

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

Login to post response