Select to view content in your preferred language

How to stop a feature layer edit save

835
4
09-27-2011 03:30 PM
DonFreeman
Emerging Contributor
I am trying to validate an email address before proceeding with edits on a SDE feature layer. The edits are taking place via a FeatureDataForm. I have the following code.
  private void FeatureLayer_BeginSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs e)
  {
   Graphic SelectedGraphic = MyFeatureDataForm.GraphicSource;
   IDictionary<string, object> attributes = SelectedGraphic.Attributes;

   var msgToAM = attributes["AMEmail"] as string;
   var msgToPM = attributes["PMEmail"] as string;
   var msgToSat = attributes["WkEndEmail"] as string;
   var msgLocation = attributes["Location"] as string;

   if (SelectedFeatureLayer.ID == "AllAvailableFeatureLayer" )
   {
    if ((msgToAM.Length == 0 || msgToAM == "Type email here") & (msgToPM.Length == 0 || msgToPM == "Type email here"))
    {
     MessageBox.Show("Please provide a valid email address.");
     return ;
    }
   }
  }

This works but the save continues. How can I stop the save after the messagebox is displayed?
Thanks.
0 Kudos
4 Replies
GarimaVyas
Emerging Contributor
Don,

You should set the AutoSave to False and listen to EditEnded instead of BeginSaveEdits. Check out this forum discussion as well.
0 Kudos
DonFreeman
Emerging Contributor
Don,

You should set the AutoSave to False and listen to EditEnded instead of BeginSaveEdits. Check out this forum discussion as well.


Thanks G. -
Sorry for my lack of experience but I don't seem to find EditEnded. The reference to it here produces an error.
     <esri:FeatureLayer ID="AllAvailableFeatureLayer" 
      Url="http://gismaps.pagnet.org/ArcGIS/rest/services/BikeCountLocations/FeatureServer/0"
      Renderer="{StaticResource AllRenderer}"
      MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
      SelectionColor="Yellow"
      OutFields="Location,AMVolunteer,AMPhone,AMEmail,PMVolunteer,PMPhone,PMEmail"
      DisableClientCaching="True"
      Where="AMVolunteer = 'Available' and PMVolunteer = 'Available'" 
      AutoSave="False"
      BeginSaveEdits="FeatureLayer_BeginSaveEdits"
      EndSaveEdits="FeatureLayer_EndSaveEdits"
      EditEnded="featureLayer_EditEnded"    >
0 Kudos
DonFreeman
Emerging Contributor
Don,

You should set the AutoSave to False and listen to EditEnded instead of BeginSaveEdits. Check out this forum discussion as well.


Got it! Thanks. It took me a while to find EditEnded as it is tied to the dataform not the feature layer. But it is very helpful. Thanks
0 Kudos
dotMorten_esri
Esri Notable Contributor
Just set e.Cancel = true;
0 Kudos