Click here to Skip to main content
15,886,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to set validations in the web methods under Web Service to limit text entry length? For instance if the text length is beyond 14 characters etc.
Posted

You can fix from textbox

<asp:textbox id="TextBox1" runat="server"  MaxLength="14" ></asp:textbox>
 
Share this answer
 
v2
C#
[WebMethod]
public string HelloWorld(string input)
{

   // you can throw new exception
   if (string.IsNullOrEmpty(input) || input.Length > 14)               
       throw new ArgumentException("Invalid Input");

   //Or you can limit the input without throwing exception  
   if (string.IsNullOrEmpty(input) &&  input.Length > 14)               
       input = input.Substring(0,14)

   // do something with input 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900