views:

33

answers:

2

I want to build user friendly error reporting. Wrong input, db connection errors and such. Problem is i need the same module be implemented for 3 different systems and to use jQuery UI modal boxes for UI.

  1. when i redirect to another page ie. db connection error i redirect to error page
  2. when i use return to same page ie. input value 1 bigger than value 2 when it should be other way around
  3. ASP.NET Ajax UpdatePanel errors, wrong input for controls within UpdatePanel that doesn't do regular postpacks.

thanks for any help with implementation...

To clarify my question

I don't need input or object validation framework. I use ASP.NET and my own business logic to validate on client and server side.

what i really need is

Help with constructing a class that will show errors to users, current process is i catch exception, wrong input value or wrong link and based on that show user friendly message. I have no time and interest in learning logging framework as from my short experience to configure any pre-made high level framework (low level to me is ASP.NET) is harder that to have your own business logic and sometimes requires application re-design... anyways... My question is pretty clear above. I need way to show centralized messages using jQuery UI.

When i redirect to another page i can save error in Session and get it on other page, if i use return to same page i cannot use Session and had no luck with overriding MasterPage public variables. When i have Ajax UpdatePanel i want again to validate data and show jQuery UI modal...

thats all

A: 

Edit: Are you logging exceptions to a database? If not I would recommend at least a rudimentary log. Other alternatives would be logging to a rolling file appender using log4net. Then, you can load the appropriate error from the logs for display to the user, regardless of how and where you are displaying the error.

See log4net

Also, a not of caution: Don't display DB connection errors to users. Log them so that you know whet is going on and then just tell the user that an error has occurred and that you are aware of it and looking into it.

End Edit

One good way to validate input is to put the validation on your data classes. This allows you to validate them at any time. I know this doesn't solve your redirection scenario which is more of a workflow issue and I hope some others can help you with that.

The reason I mentioned putting input validation on your data classes is that it allows you full control over when your validation is called and it allows you to validate multiple times, on the Client Side and Server Side for example.

A good implementation of this is the FluentValidation framework, which can be extended to automatically generate clientside validation, using the JQuery Validation plugin.

Another option which is becoming popular is Data Annotations. I don't have experience with these yet, but they are worth searching for with your favourite search engine.

Daniel Dyson
I'm interested more in how to implement centric user messaging, while on redirect, return and ajax postback rather than framework to test values themselves.
eugeneK
A: 

A different tactic would be to perform some validation on the client and since you are using jQuery there is a nice form validation plugin called Validation. Here is a good demo page. This will block you post back to the server until you have appropriate data types supplied for you form and will work with your Ajax update panels as well.

With this plugin your HTML mark up is quite straight forward:

<form id="theForm">
    <input id="startDate" type="input" class="required datetime"/>
</form>

This will eliminate the need to direct to Error.aspx, store session variables, etc.

For those error that occur on the server, you need to consider whether the user should be able to progress further should a DBConnection error be thrown. In that case you could redirect to your error page, inject your error text and have the client display the content in the jQuery dialog box.

David Robbins