I’m new to web development (though not new to WinForms developmet) and I wanted to know the correct and efficient way to handle errors both on the client side as well as the server side.
For example, user enters a bad zip code (using letters), I want to notify the user of the bad zip code entered, how do I handle this?
I’m assuming this would be on the client side but can anyone show me an example code? What scripting language should you use? Should you display a message on the screen? Should you make an error message visible? What is the standard way of doing this?
Example two: user clicks on something that runs a query in a server database. An error occurs. How do I notify the user of the error?
Usually in Win Forms I can just do this:
try
{
CreateDirectoriesAndSystemFiles();
}
catch (Exception ex)
{
ErrorLogger.LogError(ex.Source, ex.TargetSite.ToString(), "Error creating directories!; " + ex.Message);
MessageBox.Show(ex.Message, "Error creating directories!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
How can I mimic the above in a web environment?
1 For client notification, you can use Validators
Link : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx
This link is about
RequiredFieldValidatorYou have also
CompareValidator, CustomValidatoretc ….Link : http://msdn.microsoft.com/en-us/library/ms972961.aspx
That’s good solution.
2 For treatment exception, you can use
Global.asaxandApplicatio_ErrorLink : http://msdn.microsoft.com/en-us/library/24395wz3%28v=vs.100%29.aspx