I am trying to validate a textbox using RequiredFieldValidator and display error message in ValidationSummary through code behind, but I am not able to do that. My code goes here
if (txtUsrName.Text.Length == 0 || txtUsrAge.Text.Length == 0)
{
RequiredFieldValidator req = new RequiredFieldValidator();
req.ID = "Required";
req.ControlToValidate = txtUsrName.ID;
req.IsValid = false;
req.Visible = true;
req.Enabled = true;
req.ValidationGroup = "ValidationGroup";
req.ErrorMessage = "Thease are required fields";
req.InitialValue = "";
req.Text = "*";
ValidationSummary valsum = new ValidationSummary();
ValidationSummaryDisplayMode mode = new ValidationSummaryDisplayMode();
valsum.ID = "validatesummury";
valsum.HeaderText = "please correct the following errors";
valsum.DisplayMode = mode;
valsum.ShowSummary = true;
valsum.ValidationGroup = "ValidationGroup";
valsum.Visible = true;
}
Please help me with this