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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to perform these validations?

How to perform these validations?

Scheduled Pinned Locked Moved ASP.NET
questioncsharpjavascriptasp-netsysadmin
6 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.
  • J Offline
    J Offline
    just4ulove7
    wrote on last edited by
    #1

    Hi, I am having various controls say... Estimated Start Date, Estimated End Date(both are text fields with date) How can I perform these validations using Asp.net Validation Controls 1) If I input Estimated End Date, it should be greater than Estimated Start Date (if I have input it), if blank, no validation is to be done. 2) Estimated Start Date >= Todays date (if i input it) In short I want few other validations to be done based on some conditions... I want to do it without posting back to the server ... Is it possible with validation controls? or should I use javascript for it? Please Help me.. Thanks

    J M U 3 Replies Last reply
    0
    • J just4ulove7

      Hi, I am having various controls say... Estimated Start Date, Estimated End Date(both are text fields with date) How can I perform these validations using Asp.net Validation Controls 1) If I input Estimated End Date, it should be greater than Estimated Start Date (if I have input it), if blank, no validation is to be done. 2) Estimated Start Date >= Todays date (if i input it) In short I want few other validations to be done based on some conditions... I want to do it without posting back to the server ... Is it possible with validation controls? or should I use javascript for it? Please Help me.. Thanks

      J Offline
      J Offline
      Joshua Nussbaum
      wrote on last edited by
      #2

      You can use CustomValidator. Never do validation with Javascript only, while its useful to the user (no postback required to see error message) it opens up the application to hacking(javascript can be bypassed). that is why you should always do server based validation first, and if your in a good mood - write a javascript version too. 60% of statistics are made up on the spot

      J 1 Reply Last reply
      0
      • J Joshua Nussbaum

        You can use CustomValidator. Never do validation with Javascript only, while its useful to the user (no postback required to see error message) it opens up the application to hacking(javascript can be bypassed). that is why you should always do server based validation first, and if your in a good mood - write a javascript version too. 60% of statistics are made up on the spot

        J Offline
        J Offline
        just4ulove7
        wrote on last edited by
        #3

        Thanks Will try using Custom Validator...

        1 Reply Last reply
        0
        • J just4ulove7

          Hi, I am having various controls say... Estimated Start Date, Estimated End Date(both are text fields with date) How can I perform these validations using Asp.net Validation Controls 1) If I input Estimated End Date, it should be greater than Estimated Start Date (if I have input it), if blank, no validation is to be done. 2) Estimated Start Date >= Todays date (if i input it) In short I want few other validations to be done based on some conditions... I want to do it without posting back to the server ... Is it possible with validation controls? or should I use javascript for it? Please Help me.. Thanks

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, In addition to the CustomValidator, you may also consider using the CompareValidator, and set the Type property to Date. Depending on what you need, you can set the ControlToCompare or ValueToCompare properties, and also set the Operator appropriately.

          1 Reply Last reply
          0
          • J just4ulove7

            Hi, I am having various controls say... Estimated Start Date, Estimated End Date(both are text fields with date) How can I perform these validations using Asp.net Validation Controls 1) If I input Estimated End Date, it should be greater than Estimated Start Date (if I have input it), if blank, no validation is to be done. 2) Estimated Start Date >= Todays date (if i input it) In short I want few other validations to be done based on some conditions... I want to do it without posting back to the server ... Is it possible with validation controls? or should I use javascript for it? Please Help me.. Thanks

            U Offline
            U Offline
            Utsav Verma
            wrote on last edited by
            #5

            Well i code it as follows, it is written for dd/mm/yyyy format //written by Utsav Verma //purpose - to force given date in dd//mm/yyyy format lesst than second field //argument 1 - textbox having date in dd/mm/yyyy(indian) format //argument 2 - textbox2 having date in dd/mm/yyyy(indian) format function forceFirstDateLessthanSecDate(ddmmyyDate1, ddmmyyDate2) { var value1=ddmmyyDate1.value; date1 = value1.substring (0,value1.indexOf ("/"));    month1 = value1.substring (value1.indexOf ("/")+1,value1.lastIndexOf ("/"));    year1 = value1.substring (value1.lastIndexOf("/")+1, value1.length); var value2=ddmmyyDate2.value; date2 = value2.substring (0,value2.indexOf ("/"));    month2 = value2.substring (value2.indexOf ("/")+2,value2.lastIndexOf ("/"));    year2 = value2.substring (value2.lastIndexOf("/")+2, value2.length); var td=new Date(year1+'/'+month1+'/'+date1); var td2=new Date(year2+'/'+month2+'/'+date2); if(td.getTime()>=td2.getTime()) { alert(ddmmyyDate1.name + ' should be less ' + ddmmyyDate2.name ); return false; } else return true; } Utsav

            J 1 Reply Last reply
            0
            • U Utsav Verma

              Well i code it as follows, it is written for dd/mm/yyyy format //written by Utsav Verma //purpose - to force given date in dd//mm/yyyy format lesst than second field //argument 1 - textbox having date in dd/mm/yyyy(indian) format //argument 2 - textbox2 having date in dd/mm/yyyy(indian) format function forceFirstDateLessthanSecDate(ddmmyyDate1, ddmmyyDate2) { var value1=ddmmyyDate1.value; date1 = value1.substring (0,value1.indexOf ("/"));    month1 = value1.substring (value1.indexOf ("/")+1,value1.lastIndexOf ("/"));    year1 = value1.substring (value1.lastIndexOf("/")+1, value1.length); var value2=ddmmyyDate2.value; date2 = value2.substring (0,value2.indexOf ("/"));    month2 = value2.substring (value2.indexOf ("/")+2,value2.lastIndexOf ("/"));    year2 = value2.substring (value2.lastIndexOf("/")+2, value2.length); var td=new Date(year1+'/'+month1+'/'+date1); var td2=new Date(year2+'/'+month2+'/'+date2); if(td.getTime()>=td2.getTime()) { alert(ddmmyyDate1.name + ' should be less ' + ddmmyyDate2.name ); return false; } else return true; } Utsav

              J Offline
              J Offline
              just4ulove7
              wrote on last edited by
              #6

              Hi,,, I have a simple check, the way u suggested above...like.. If txtActEndDate(textbox) is not null....the cmbPercComplete( percentage complete) should be 100. If not its invalid. I want to use a server side script, as for all the validations I am not giving any alerts. private void fn_PercComplete(Object sender, ServerValidateEventArgs e) { if (txtActEndDate.Text !="") { if (cmbPercComplete.SelectedItem.Text!="100") { e.IsValid=false; return; } } e.IsValid=true; } .aspx code If I write ClientSidevalidadation script, wl it serve my purpose? I mean, if i return false from the client script, wl the error message in the validator be displayed.. i tried it but its not working...I am not sure whether it should or not??? Thanks

              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