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. requiredfieldvalidation for 2 listboxes

requiredfieldvalidation for 2 listboxes

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
2 Posts 2 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.
  • L Offline
    L Offline
    lehya
    wrote on last edited by
    #1

    User needs to choose either of 2 listboxes... How to set a requiredfieldvalidator for this problem? If none of listboxes r selected, requirefieldvalidator will throw a error that none is been selected..Look into the problem!!!

    S 1 Reply Last reply
    0
    • L lehya

      User needs to choose either of 2 listboxes... How to set a requiredfieldvalidator for this problem? If none of listboxes r selected, requirefieldvalidator will throw a error that none is been selected..Look into the problem!!!

      S Offline
      S Offline
      Sushant Duggal
      wrote on last edited by
      #2

      Hi, You can do this simply with javascript. Here is the Code for that: //////// ASPX PAGE CODE /***** JAVASCRIPT FUNCTION *****/ function checkDropDowns() { var ddl1 = document.getElementById('ddl1'); var ddl2 = document.getElementById('ddl2'); if(ddl1.options[0].selected == true && ddl2.options[0].selected == true) { alert("Please Select One Value From Atleast One DropDown Box!!"); return false; } } /****************************/ /****** ASPX PAGE BODY **********/

      Select Item Item 1 Item 2 Item 3 Select Item Item 1 Item 2 Item 3

      /********** CODE BEHIND FILE ***********/ IN PAGE LOAD EVENT ADD THE FOLLOWING CODE : Button1.Attributes.Add("OnClick","javascript:return checkDropDowns();"); /****************************************/ I hope this will solve your problem Thanks,:) Sushant Duggal.

      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