Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im having the
three groups of validations
commoninfo
femaleinfo
maleinfo
depending upon the visitor of the site i want make decision at time i.e commoninfo& femaleinfo is one situation so how can i get the validation group names at run time plz help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted

Hi,

you can check this once for your requirement.

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        function changeval() {
            if (document.getElementById("chb1").checked) {
                RequiredFieldValidator1.validationGroup = "g1";
            }
            else {
                RequiredFieldValidator1.validationGroup = "";
            }

            
            if (document.getElementById("Chb2").checked) {
                RequiredFieldValidator2.validationGroup = "g1";
            }
            else {
                RequiredFieldValidator2.validationGroup = "";
            }
            if (document.getElementById("Chb3").checked) {
                RequiredFieldValidator3.validationGroup = "g1";
            } else {
                RequiredFieldValidator3.validationGroup = "";
            }
            if (document.getElementById("Chb4").checked) {
                RequiredFieldValidator4.validationGroup = "g1";

            } else {
                RequiredFieldValidator4.validationGroup = "";
            }
            

        }
     
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <asp:requiredfieldvalidator id="RequiredFieldValidator1" controltovalidate="TextBox1" validationgroup="g1" runat="server" errormessage="RequiredFieldValidator" xmlns:asp="#unknown"></asp:requiredfieldvalidator><br />
        <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox>
          <asp:requiredfieldvalidator id="RequiredFieldValidator2" controltovalidate="TextBox2" validationgroup="g1" runat="server" errormessage="RequiredFieldValidator" xmlns:asp="#unknown"></asp:requiredfieldvalidator><br />
        <asp:textbox id="TextBox3" runat="server" xmlns:asp="#unknown"></asp:textbox>
          <asp:requiredfieldvalidator id="RequiredFieldValidator3" controltovalidate="TextBox3" validationgroup="g1" runat="server" errormessage="RequiredFieldValidator" xmlns:asp="#unknown"></asp:requiredfieldvalidator><br />
        <asp:textbox id="TextBox4" runat="server" xmlns:asp="#unknown"></asp:textbox>
          <asp:requiredfieldvalidator id="RequiredFieldValidator4" controltovalidate="TextBox4" validationgroup="g1" runat="server" errormessage="RequiredFieldValidator" xmlns:asp="#unknown"></asp:requiredfieldvalidator><br />
        <asp:button id="Button1" runat="server" text="Button" validationgroup="g1" xmlns:asp="#unknown" /><br />
       
        <input type ="checkbox" id="chb1" value ="TextBox1" />TextBox1<br />
         <input type ="checkbox" id="Chb2" value ="TextBox2" />TextBox2<br />
          <input type ="checkbox" id="Chb3" value ="TextBox3" />TextBox3<br />
           <input type ="checkbox" id="Chb4" value ="TextBox4" />TextBox4<br />
        <input type ="button" id="btnchange" value="Set Validation" onclick="changeval()" />
    </div>
    </form>
</body>
</html>


In the above page run it as it is then

check checkbox which textbox to validate then click set validate.

after that click Button you'll see validation for textboxes which you selected

All the Best
 
Share this answer
 
Comments
sandhya.T 2011 21-Oct-11 5:52am    
thanq so much
its exactly what i want but its become very large code in my application
Muralikrishna8811 21-Oct-11 6:47am    
you can upgrade it

I mean you can reduce it by using jquery or controlling from server side
sandhya.T 2011 22-Oct-11 1:13am    
how can i reduce it
Muralikrishna8811 22-Oct-11 4:16am    
based on your requirement.

I mean If you want to check at start of page then write it in pageload

If you want to change that settings in client side just invoke which textboxes you want to validate
Hi

This May be help you
http://forums.asp.net/t/1288300.aspx/2/10


Thanx
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900