Please find the below options for validation, may be these would help.
Options 1:
if (Condition satisfied)
{
//Code for Update Logic
}
Else
{
throw new Exception("The Date format is not correct format");
}
Option 2:
string sMessage;
sMessage = " The Date format is not correct format ";
str = "<script language=javascript> var strTrueFalse; ";
str = str + " alert('" + sMessage + "');";
str = str + "</script>";
Page.RegisterStartupScript("ppname", str);
Option 3:
In App_Code you can write common function that would be used in project.
public static void DisplayUserMessage(int nMessageTypeID)
{
string strScript = string.Empty;
strScript = "<script type='text/javascript'>alert('";
if (nMessageTypeID == 1)
{
strScript = strScript + Resources.Multilingual.Recordhasbeensavedsuccessfully;
}
else if (nMessageTypeID == 2)
{
strScript = strScript + Resources.Multilingual.Recordhasbeenupdatedsuccessfully;
}
else if (nMessageTypeID == 3)
{
strScript = strScript + Resources.Multilingual.Recordshasbeendeletedsuccessfully;
}
else if (nMessageTypeID == 4)
{
strScript = strScript + Resources.Multilingual.Recordshasbeeninactivateddeletedsuccessfully;
}
strScript = strScript + "');</script>";
System.Web.UI.Page P = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
ScriptManager.RegisterStartupScript(P, typeof(System.Web.UI.Page), "alertScript", strScript, false);
}
In application you can use like that
if (Condition satisfied)
{
//Code for Update Logic
}
Else
{
PMAP_Common_Methods.DisplayUserMessage(2);
}