Hi I have a validation method,
public string ValidateField()
{
string strtemp = "";
strtemp += ValidateField("Visitor_Name", visitor_name.Text, 10, 50, "string", true);
strtemp += ValidateField("Phone_Number", phone_number.Text, 5, 20, "string", true);
strtemp += ValidateField("Contact_Number", contact_number.Text, 4, 25, "string", true);
strtemp += ValidateField("Visited_Date", DropDownList1.SelectedValue, 1, 30, "int", true);
//strtemp += ValidateField("V_Id", v_id.SelectedValue, 2, 35, "int", false);
return strtemp;
}
public static string ValidateField(string fieldname, string fieldvalue, int minLength, int maxLength, string fieldType, bool mandatory)
{
string returnValue = "";
try
{
if (mandatory = true && fieldvalue == "")
{
returnValue += "" + fieldvalue + " should not be empty";
}
if (fieldvalue.Trim().Length < minLength)
{
returnValue += "" + fieldvalue + " length should be greater than or equal to minimum length" + minLength + "";
}
if (fieldvalue.Trim().Length > maxLength)
{
returnValue += "" + fieldvalue + " length should be less than or equal to max lenght";
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
return returnValue;
}
And inside the button click event the validation working like
if (ValidateField() == "")
{
output = usbll.insertBAL(userval);
Response.Write("Record inserted successfully");
}
It working corectly...But It is not showing error message.So how to show the error message that is returned from the above condition ValidateField()...If the condition not satisfied i want to show a error message like length should be greater than or equal to minimum length and so on ..
Regards,
Bebins V