I am working with a dynamic data site and there are some business rules I should validate before allowing an insert of new data or update
I am working with the list details page and I have the default dynamic validator to validate the details view1 and a summary validation control
My issue is I am able to validate but unable to display the error message in the validation summary, I get an unhandled exception, the exception is thrown but it is not handled by the validation summary
any idea how can I achieve this
This is what I am doing for the validation( I am using linq to entity or the ADO.Net framwork EFv4)
public partial class MYDataContext
{
partial void OnContextCreated()
{
this.SavingChanges += new
System.EventHandler(OnSavingChanges);
}
public void OnSavingChanges(object sender, System.EventArgs e)
{
var stateManager =
((MYDataContext)sender).ObjectStateManager;
var changedEntities = ObjectStateManager.GetObjectStateEntries
(EntityState.Modified | EntityState.Added);
foreach (ObjectStateEntry stateEntryEntity in
changedEntities)
{
if (stateEntryEntity.Entity is MyEntity)
{
MyEntity uoc = (MyEntity)stateEntryEntity.Entity;
ValidateOutageCode(uoc.field1, uoc.field2);
sman056
0 Points
2 Posts
Dynamic Data Custom Validation Validation summary
Jun 19, 2010 03:10 PM|LINK
Hello
I am working with a dynamic data site and there are some business rules I should validate before allowing an insert of new data or update
I am working with the list details page and I have the default dynamic validator to validate the details view1 and a summary validation control
My issue is I am able to validate but unable to display the error message in the validation summary, I get an unhandled exception, the exception is thrown but it is not handled by the validation summary
any idea how can I achieve this
This is what I am doing for the validation( I am using linq to entity or the ADO.Net framwork EFv4)
public partial class MYDataContext
{
partial void OnContextCreated()
{
this.SavingChanges += new
System.EventHandler(OnSavingChanges);
}
public void OnSavingChanges(object sender, System.EventArgs e)
{
var stateManager =
((MYDataContext)sender).ObjectStateManager;
var changedEntities = ObjectStateManager.GetObjectStateEntries
(EntityState.Modified | EntityState.Added);
foreach (ObjectStateEntry stateEntryEntity in
changedEntities)
{
if (stateEntryEntity.Entity is MyEntity)
{
MyEntity uoc = (MyEntity)stateEntryEntity.Entity;
ValidateOutageCode(uoc.field1, uoc.field2);
}
}
}
void ValidateOutageCode(string field1, string field2)
{
if (field1 == field2)
{
throw new ValidationException("the error message I like to display in the detailsview ValidationAttribute summary");
}
}
}