Advertisement

04.11.2008 at 01:19AM PDT, ID: 23314409
[x]
Attachment Details

.net required field validation (how to turn on/off client side?)

Asked by alfie77 in Programming for ASP.NET, JavaScript, .NET

Hi,
I have a page that has the following div:

<div id="divClient2" style="display:none" runat="server" >
    <asp:Label ID="lblClient2" SkinID="form" runat="server">&nbsp</asp:Label>
    <asp:DropDownList ID="ddlTitle2" SkinID="ddlS" runat="server">
    </asp:DropDownList>
    <asp:RequiredFieldValidator ID="valTitle2" runat="server" ControlToValidate="ddlTitle2" Text="*" InitialValue="Title"></asp:RequiredFieldValidator>
    <asp:TextBox ID="txtForename2" SkinID="txtL" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="valForename2" runat="server" ControlToValidate="txtForename2" InitialValue="firstname" Text="*"></asp:RequiredFieldValidator>    
    <asp:TextBox ID="txtSurname2" SkinID="txtL" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="valSurname2" runat="server" ControlToValidate="txtSurname2" InitialValue="surname" Text="*"></asp:RequiredFieldValidator>
</div>

As you can see the initial value is dispaly:none and some javascript toggles the div to be displayed or not:

function ShowHide()
{
    var SelectedValue = document.getElementById('<%=ddlClientNumber.ClientID%>').value;
    if(SelectedValue == "2")
    {
        document.getElementById('<%=divClient2.ClientID%>').style.display = 'block';        
    }
    else
    {  
        document.getElementById('<%=divClient2.ClientID%>').style.display = 'none';    
    }        
}

Now, if the div is not displayed, validation is still required on the 3 "hidden" fields, what is the best workaround for this - I would like to validate the field if displayed and not if hidden???

Thanks in advanceStart Free Trial
[+][-]04.11.2008 at 05:46AM PDT, ID: 21333639

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 08:34AM PDT, ID: 21335231

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 11:07AM PDT, ID: 21336661

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 11:36AM PDT, ID: 21336929

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.12.2008 at 12:12AM PDT, ID: 21340132

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, JavaScript, .NET
Sign Up Now!
Solution Provided By: NazoUK
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628