You are here:   Home
Register   |  Login

Captured Technology - Blog

Minimize

Turning On/Off APS.Net Client Side Validation

Mar 6

Written by:
3/6/2009 11:44 AM  RssIcon

Turning On/Off APS.Net Client Side Validation

Javascript has a built in function, ValidatorEnable, to turn on or turn off client validation so you can validate certain controls under only certain conditions. The code attached shows how to limit the validation on a textbox depending on value of a dropdown list. The code also only displays the textbox when the same condition is true.

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function Validate()
        {
            if(document.getElementById("DropDownList1").selectedIndex < 2)
                {
        document.getElementById("TextBox1").disabled = true;
        ValidatorEnable(document.getElementById("valrqdOther"), true);
        }
            else
        {
        document.getElementById("TextBox1").disabled = false;
        ValidatorEnable(document.getElementById("valrqdOther"), false);
        }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" >
            <asp:ListItem Text="1"></asp:ListItem>
            <asp:ListItem Text="2"></asp:ListItem>
            <asp:ListItem Text="3"></asp:ListItem>
            <asp:ListItem Text="4"></asp:ListItem>
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valrqdOther" runat="server" 
ControlToValidate="TextBox1" ErrorMessage="- TextBox1 is a required field."
Display="Dynamic" InitialValue="" Enabled="false"></asp:RequiredFieldValidator> </div> </form> public partial class SomeUserClass : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DropDownList1.Attributes.Add("onchange", "javascript:return Validate()"); } }

Tags:
Categories:

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

FaceBook

Minimize

Mobile Version

Minimize
Add CapturedTech - Technology Mippin widget

Translate

Minimize

Sponsors

Minimize

Recent Comments

Minimize
Re: Three Benefits to Using a Royalty-Free Image on Your Website or Blog
I also prefer to use royalty-free images. They give more credibility in your site or blog posts.
Re: Websites vs. Facebook Pages (Infographic)
Internet can be very useful for small business to market them self, there is always some free way to reach your audience via Internet.
Re: Is Keyword Density Still Important For On Page SEO
The search engines hadn’t quite caught up yet. As a result, it wasn’t uncommon to see sites rank highly when their content read something like this.that they follow SEO best practices than you will by trying to figure out a way to get your keywords into your page content another one or two times.
Re: Websites vs. Facebook Pages (Infographic)
Very interesting topic, infographics was a new concept for me, will definitely use it.
Re: Reducing Small Business Blues
Running a business is tough and you are right, most of the time you are the core aspect of each area of a business. I don't think I could handle doing my own accounting, like you I am too terrible with numbers!

u comment, i follow