disable validation of hidden div or row

22 Mar

in this tutorial  try to resolve the issue of Validation when the dropdownlist hidden which show only when radio button click .the problem i face when radio button click or not click which give error message you must select value of dropdownlist .so resolve the problem with java script apply this procedure on checkbox or anyone.

<table cellpadding=”0″ cellspacing=”0″>
<input id=”CbBranch” runat=”server” type=”radio” value=”Branch” name=”ctl00$ContentPlaceHolder1$rbl2″
onclick=”validateFormApp()” />
<label for=”ctl00_ContentPlaceHolder1_rbl2_4″>
<td style=”padding: 3px 0 0 4px; vertical-align: middle;”>
<div id=”trBranch” style=”display: none;”>
<asp:DropDownList ID=”ddlBranch” runat=”server” CssClass=”input”>
<asp:ListItem Value=”-1″>Select Branch</asp:ListItem>
<asp:ListItem>Chesapeake Branch</asp:ListItem>
<asp:ListItem>Largo Branch</asp:ListItem>
<asp:ListItem>Cherokee Branch</asp:ListItem>
<asp:ListItem>Reston Branch</asp:ListItem>
<asp:ListItem>McPherson Square Branch</asp:ListItem>
<asp:ListItem>Potomac Avenue </asp:ListItem>
<asp:ListItem>Columbia Heights Branch</asp:ListItem>

ID=”rfvbranch” runat=”server” ControlToValidate=”ddlBranch”
Display=”None” ErrorMessage=”Select Branch ” InitialValue=”-1″ ValidationGroup=”grpSur”></asp:RequiredFieldValidator>

Javascript Function for hide and show and also check the validation

<script language=”JavaScript” type=”text/JavaScript”>
function validateFormApp() {

var tr_branch = document.getElementById(‘trBranch’);

var rfv_branch = document.getElementById(‘<%=rfvbranch.ClientID %>’);

if (document.getElementById(“<%=CbBranch.clientid %>”).checked == true) {

document.getElementById(‘trBranch’).style.display = ”

ValidatorEnable(rfv_branch, true);

else {

document.getElementById(‘trBranch’).style.display = ‘none’

ValidatorEnable(rfv_branch, false);

//onclick=”if(this.checked==true){document.getElementById(‘trBranch’).style.display=”;} else{document.getElementById(‘trBranch’).style.display=’none’ EnableValidation=”false”;}”

Onload disable the validation of Hidden div or row of the dropdownlisth

<script language=”JavaScript” type=”text/JavaScript”>
//call after page loaded
window.onload = validateFormApp;

Leave a comment

Posted by on March 22, 2011 in ASP.Net Validation


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: