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