protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { // Perform validation on the input if (args.Value == "") { args.IsValid = false; } else { args.IsValid = true; } }
protected void Page_Load(object sender, EventArgs e) { // Add a validation event handler for a TextBox control TextBox1.ServerValidate += new ServerValidateEventHandler(TextBox1_Validate); } protected void TextBox1_Validate(object source, ServerValidateEventArgs args) { // Perform validation on the input int value; if (!int.TryParse(args.Value, out value)) { args.IsValid = false; } else { args.IsValid = true; } }This example shows how to add a validation event handler for a TextBox control and perform input validation on the server-side. The validation method checks if the input provided by the user is a valid integer or not. The package library for System.Web.UI.WebControls is part of the .NET Framework class library.