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. validation

validation

Scheduled Pinned Locked Moved ASP.NET
help
3 Posts 3 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.
  • R Offline
    R Offline
    rakeshs312
    wrote on last edited by
    #1

    Hai all, I have a multiline text box. I want to limit the charaters inside the textbox to 250. For that i written this code in cs file i added the attributes like(txtEmpWithA is my textbox name)

    this.txtEmpWithA.Attributes.Add("OnKeyPress", "txtreason_limit(event)");

    and the function in aspx file

    function txtreason_limit(evt)
    {

    if(document.form1.txtEmpWithA .value.length == 250)
                 { 
                 evt.keyCode = 0;
                 return;
                 }
             }
    

    This is working fine when i am typing there ,but if i copy and paste,it taking more than 250 charactors

    Please help

    P P 2 Replies Last reply
    0
    • R rakeshs312

      Hai all, I have a multiline text box. I want to limit the charaters inside the textbox to 250. For that i written this code in cs file i added the attributes like(txtEmpWithA is my textbox name)

      this.txtEmpWithA.Attributes.Add("OnKeyPress", "txtreason_limit(event)");

      and the function in aspx file

      function txtreason_limit(evt)
      {

      if(document.form1.txtEmpWithA .value.length == 250)
                   { 
                   evt.keyCode = 0;
                   return;
                   }
               }
      

      This is working fine when i am typing there ,but if i copy and paste,it taking more than 250 charactors

      Please help

      P Offline
      P Offline
      padmanabhan N
      wrote on last edited by
      #2

      this can be handled by 2 ways 1) by writing the code for validating whether the text is greater than the length if (TextBox1.Text.Length > 250) { Response.Write("The text is greater than 250"); } (or) 2) disable copy and paste. function DisableCopyPaste() //Prevents Copy, Paste, Select, ContextMenu in TextBox and MultiLine TextBox controls. { var myForm = document.forms[0]; for (var i = 0; i < myForm.elements.length; i++) { var elementType = myForm.elements[i].type; if (elementType == 'text' || elementType == 'textarea') { document.getElementById(myForm.elements[i].id).onpaste = function(){return false;}; document.getElementById(myForm.elements[i].id).oncontextmenu = function(){return false;}; document.getElementById(myForm.elements[i].id).onselectstart = function(){return false;}; document.getElementById(myForm.elements[i].id).ondragstart = function(){return false;}; } } } //paste this in page load ClientScript.RegisterStartupScript(this.GetType(), "StartUpScript", @"DisableCopyPaste();");

      Padmanabhan

      1 Reply Last reply
      0
      • R rakeshs312

        Hai all, I have a multiline text box. I want to limit the charaters inside the textbox to 250. For that i written this code in cs file i added the attributes like(txtEmpWithA is my textbox name)

        this.txtEmpWithA.Attributes.Add("OnKeyPress", "txtreason_limit(event)");

        and the function in aspx file

        function txtreason_limit(evt)
        {

        if(document.form1.txtEmpWithA .value.length == 250)
                     { 
                     evt.keyCode = 0;
                     return;
                     }
                 }
        

        This is working fine when i am typing there ,but if i copy and paste,it taking more than 250 charactors

        Please help

        P Offline
        P Offline
        Perry Holman
        wrote on last edited by
        #3

        It's a better way to use a custom validation control provided by the VS IDE.

        Welcome to www.softwaretree.net! This website is generated completely by static html pages transforming technology. You can find many excellent audio/video tools there!

        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