locked
DynamicValidator not catching exceptions when deleting. RRS feed

  • Question

  • User-380105403 posted

    I have installed the 3.5 SP1 beta.

    I have put some code in the OnValidate handler to return some friendly error messages.  The exception thrown on Insert/Update displays fine in the DynamicValidator.

    Any of the errors thrown on Delete are not handled by the DynamicValidator and ends up as an unhandled exception.

     

    partial void OnValidate(ChangeAction action)

    {

    if (action == ChangeAction.Insert || action == ChangeAction.Update)

    {

    RequisitionDataContext rdc = new RequisitionDataContext();

    var query = from l in rdc.Locations.Where(x => x.LocationName == LocationName && x.LocationID != LocationID) select l;

    if (query.Count() > 0)throw new ValidationException("A location already exists with this name. Please select another.");

     

    }

    if (action == ChangeAction.Delete)

    {

    RequisitionDataContext rdc = new RequisitionDataContext();

    var query = from l in rdc.vwLocation_Items.Where(x => x.LocationID == LocationID && Convert.ToBoolean(x.Available) == true) select l;

    if (query.Count() > 0)

    throw new ValidationException("You cannot delete a location which has items associated with it.");

    var query2 = from l in rdc.Users.Where(x => x.LocationID == LocationID) select l;

    if (query2.Count() > 0)

    throw new ValidationException("You cannot delete a location to which users are assigned.");

    var query3 = from l in rdc.User_Locations.Where(x => x.LocationID == LocationID) select l;

    if (query3.Count() > 0)throw new ValidationException("You cannot delete a location which has users associated with it.");

    }

    }

     

    Thursday, June 26, 2008 5:58 AM

Answers

All replies

  • User660823006 posted

    Please try our latest runtime bits at: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14474. We had some issues in some of our Details/Insert templates that would immediately redirect back to the main list page even if an error had occured. The templates should be corrected in the lastet release listed above. Let me know if it solves you problem.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 26, 2008 12:13 PM
  • User-1759624489 posted

     I have the same problem and I am using 3.5 Sp1.

     

    Please somebody help me at this post.

    http://forums.asp.net/t/1312856.aspx

     

    Thanks

    Friday, August 29, 2008 4:36 PM