This project is read-only.

Validations and Feedback user

Feb 12, 2013 at 10:23 PM
Congratulations. I really like "Navigation for ASP.NET Web Forms", I think it's a natural evolution of web applications and would like to learn and use it. I worry that there is little documentation and little information on the web but I will try. :)

I'd like to incorporate it into a project N-Tier with EF, where data validations like them at the server level, the question then is: How I can do this?, The other question, assuming I have ObjectDataSource and use NavigationDataParameter, this being a ref parameter, as follows:
<asp:ObjectDataSource ID="DisplaySource" runat="server" TypeName="Employee.Controllers.EmployeeController" SelectMethod="GetEmployee">
<nav:NavigationDataParameter Name="errorMessage" />
public Employee GetEmployee (ref string errorMessage), how I can implement it?

Thanks in advance, Pablo
Feb 13, 2013 at 9:37 PM
Hi Pablo,

It's always great to be asked a question, but it's especially nice when it's as complimentary as yours.

The Navigation framework doesn't provide any validation framework, but I'll try and explain the ASP.NET data binding way to do EF validation in an N-tier project. Let's assume you've got a FormView that's data bound to an Update method in your EmployeeController class. How do you communicate EF data validation failures on your Employee class back to the UI?

Before VS 2012 the only way was to have your Update method throw an Exception if the validation fails. Then your code behind could listen to the FormView's ItemUpdated event, check for the exception and set the KeepInEditMode on the FormViewUpdatedEventArgs passed in. This is messy. But the good news is that data binding has been overhauled in VS 2012. Now there's no need to throw Exceptions or add code behind because it can all be handled using the new ModelState parameter passed into your Update method.

Are you able to use VS 2012? If you can then there's no need to use ObjectDataSources for data binding any more. But I'll assume you can't use VS 2012 when answering your second question.

The first stage when using the Navigation framework is to create your StateInfo configuration because this contains the details of your pages. So, we'll create an Employee Details State:
    <dialog key="Employee" initial="Details" path="~/Details.aspx">
        <state key="Details" page="~/Details.aspx"/>
Then in your Details.aspx you need to add a FormView with it's DataSourceID property set to the ID of your ObjectDataSource control:
<asp:FormView runat="server" DataSourceID="DisplaySource">
        <%#: Eval("Name") %>
<asp:ObjectDataSource ID="DisplaySource" runat="server" TypeName="Employee.Controllers.EmployeeController" SelectMethod="GetEmployee">
        <nav:NavigationDataParameter Name="Id" />
Then your GetEmployee method would look something like this:
public Employee GetEmployee(string Id)
    return new Employee() { Name = "Pablo" };
The Id passed into the GetEmployee method is currently empty but that's because we haven't passed any Navigation Data. This would probably be passed in from a previous page when an Employee is selected from a list. Would you like me to show how this is done?

There's more documentation on the Navigation framework than you might think. I've written quite a lot of articles and built various samples about it. Would you like me to provide links to some of them?

I really hope my answer has helped you.