Zoom Asp.net

enable disable validation group Client Side using Javascript in asp.net

by chintan prajapati on Mar.10, 2008, under ASP.net, Javascript, ValidationGroup

Recently i faced problem in validating Address Control which basically depends on selection of radio button.below is the figure of problem.

Validation Group Example

Here All controls below Gift to this Address Radiobutton should not fire validation if it is not checked. Asp.net Simply does all validation and shows all errormessage even if Gift to this Address is not selected, so all you have to do is create validation group for left address block called “ADDRESS” by assigning ValidationGroup Property value of “ADDRESS”.

Put this code for Button named “Done”

OnClientClick=”EnableDisableValidation();”

javascript function EnableDisableValidation() looks like below.

function EnableDisableValidation()
{
if($L(’rdbMyAddress’).checked)
{
return Page_ClientValidate(’Address’);
}
else if($L(’rdbAddressGift’).checked)
{
if( Page_ClientValidate())
{ return true;}
else
{ return false;}
}
}

Where $L is replacement of document.getElementById(”);

Page_ClientValidate(’Address’) function Validates All Control having property ValidationGroup =”Address”.

Where as Page_ClientValidate() Blindly validates all validation Controls within page.

I hope now you are clear with idea of customized validation control.

i can share more code with you if still not clear.

feel free to put your comments :)
happy codding :)

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Google
  • Technorati
4 comments for this entry:
  1. Bill

    I tried your method and it seems that the javascript function was never called during the process, instead it went straight to the validation first, can you help? Thanks

  2. Bart van der Werf

    Thanks, that’s just what I was looking for!

    Regards, Bart

  3. Maharsh

    but i can’t understand
    from where 2 start& how to go further
    implementation & reach at the end for fetching addresses/contacts of yahoo/gmail through c# code

  4. Jmadden

    Can you post more code or share your actual ASPX & Code behind files? I couldn’t get this to work.
    Thanks!

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Failed creating file mapping PHP Fatal error: Failed creating file mapping in Unknown on line 0 PHP Fatal error: XCache: Cannot create shm in Unknown on line 0