Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Validations

Validations

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhattiprolu
    wrote on last edited by
    #1

    hi all, in my web page i have one dropdown list it contains Email and Phone values. and i hav email and phone textboxes. now the thing is if i select email from drop down list i want Email as mandatory, if i select phone from dropdown list i want Phone as mandatory! how to achieve this? i have written my code as follows! if (ddlCmethod.SelectedValue == "Telephone") { valmanEmail.IsValid = false; valmanPhone.IsValid = true; } else { valmanPhone.IsValid = false; valmanEmail.IsValid = true; }

    S S 2 Replies Last reply
    0
    • B bhattiprolu

      hi all, in my web page i have one dropdown list it contains Email and Phone values. and i hav email and phone textboxes. now the thing is if i select email from drop down list i want Email as mandatory, if i select phone from dropdown list i want Phone as mandatory! how to achieve this? i have written my code as follows! if (ddlCmethod.SelectedValue == "Telephone") { valmanEmail.IsValid = false; valmanPhone.IsValid = true; } else { valmanPhone.IsValid = false; valmanEmail.IsValid = true; }

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      i think if the valmanPhone is required field validator or any validator you should not set IsValid property you need to set IsRequired property true ro false

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      B 1 Reply Last reply
      0
      • S Sandeep Akhare

        i think if the valmanPhone is required field validator or any validator you should not set IsValid property you need to set IsRequired property true ro false

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

        B Offline
        B Offline
        bhattiprolu
        wrote on last edited by
        #3

        thanks for the reply :) but there is no IsRequired property.

        S S 2 Replies Last reply
        0
        • B bhattiprolu

          thanks for the reply :) but there is no IsRequired property.

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          OOPs :sigh: What problem are you facing is it not firing the validation properly ?

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          B 1 Reply Last reply
          0
          • B bhattiprolu

            thanks for the reply :) but there is no IsRequired property.

            S Offline
            S Offline
            Spunky Coder
            wrote on last edited by
            #5

            for what control u are trying to set the IsValid=false ..i.e is valmanEmail is a validator control? if so then set Enabled = false;

            Koushik

            B 1 Reply Last reply
            0
            • S Sandeep Akhare

              OOPs :sigh: What problem are you facing is it not firing the validation properly ?

              Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

              B Offline
              B Offline
              bhattiprolu
              wrote on last edited by
              #6

              actually thing is... i want to made a field is require as per the dropdownlist item selected. means if i select Email from my dropdown list the the Email field must become mandatory and phone field will be normal means not mandatory. if i select Phone then phone filed must become mandatory and Email field will be not mandatory. how to achieve this!!! :confused:

              1 Reply Last reply
              0
              • S Spunky Coder

                for what control u are trying to set the IsValid=false ..i.e is valmanEmail is a validator control? if so then set Enabled = false;

                Koushik

                B Offline
                B Offline
                bhattiprolu
                wrote on last edited by
                #7

                Thanks for reply... :) no its not working!!!! :(

                1 Reply Last reply
                0
                • B bhattiprolu

                  hi all, in my web page i have one dropdown list it contains Email and Phone values. and i hav email and phone textboxes. now the thing is if i select email from drop down list i want Email as mandatory, if i select phone from dropdown list i want Phone as mandatory! how to achieve this? i have written my code as follows! if (ddlCmethod.SelectedValue == "Telephone") { valmanEmail.IsValid = false; valmanPhone.IsValid = true; } else { valmanPhone.IsValid = false; valmanEmail.IsValid = true; }

                  S Offline
                  S Offline
                  Shanmugam R
                  wrote on last edited by
                  #8

                  You can achive through Dropdown on click Javascript event. Based on the selected value function EnableValidator() { if(document.getElementById('<%=ddlCmethod.ClientID%>').value=='Telephone') { ValidatorEnable(document.getElementById('<%=valmanEmail.ClientID%>'), false); ValidatorEnable(document.getElementById('<%=valmanPhone.ClientID%>'), true); } else { ValidatorEnable(document.getElementById('<%=valmanEmail.ClientID%>'), true); ValidatorEnable(document.getElementById('<%=valmanPhone.ClientID%>'), false); } } Just call 'EnableValidator()' function on click of the dropdownlist This will work.

                  Shanmugam R

                  B 1 Reply Last reply
                  0
                  • S Shanmugam R

                    You can achive through Dropdown on click Javascript event. Based on the selected value function EnableValidator() { if(document.getElementById('<%=ddlCmethod.ClientID%>').value=='Telephone') { ValidatorEnable(document.getElementById('<%=valmanEmail.ClientID%>'), false); ValidatorEnable(document.getElementById('<%=valmanPhone.ClientID%>'), true); } else { ValidatorEnable(document.getElementById('<%=valmanEmail.ClientID%>'), true); ValidatorEnable(document.getElementById('<%=valmanPhone.ClientID%>'), false); } } Just call 'EnableValidator()' function on click of the dropdownlist This will work.

                    Shanmugam R

                    B Offline
                    B Offline
                    bhattiprolu
                    wrote on last edited by
                    #9

                    hey thanks for ur response! but there is no property called OnClick for dropdown list!!!

                    S 1 Reply Last reply
                    0
                    • B bhattiprolu

                      hey thanks for ur response! but there is no property called OnClick for dropdown list!!!

                      S Offline
                      S Offline
                      Shanmugam R
                      wrote on last edited by
                      #10

                      Just include the following code on server side (Form Load event). drpList.Attributes.Add("onchange", "JavaScriptFunctionName();"); or drpList.Attributes.Add("onclick", "JavaScriptFunctionName();"); We can add properties using the Attributes method.

                      Shanmugam R

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups