Select to view content in your preferred language

Feature Layer update kills the save

1097
5
02-11-2011 01:24 PM
DonFreeman
Emerging Contributor
I have a FeatureDataForm with and EditEnded handler like this.
private void MyFeatureDataForm_EditEnded(object sender, EventArgs e)
   {
   foreach (Layer lyr in MyMap.Layers)
    {
    if (lyr is FeatureLayer)
     {
     FeatureLayer featureLayer = lyr as FeatureLayer;
     featureLayer.SaveEdits();
     featureLayer.Refresh();
     featureLayer.Update();
          }
    }      
   }

This cycles through all the FeatureLayers on the map and attempts to refresh them. Supposedly I only need the Update() command to do this but the SaveEdits() and Refresh() commands are in there for experimentation. I found that there is no benefit from the first 2, however if the Update() command is included the edit which was just made seems to get cancelled and nothing changes on the map or its data. Client caching is off and IsReadOnly is set to false. Anybody know what gives here?

Thanks
0 Kudos
5 Replies
DonFreeman
Emerging Contributor
If you want to save edits explicitly, you need to set AutoSave on the FeatureLayer to False. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay....

The following documentation explains SaveEdits, Update and Refresh:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.GraphicsLa...


Hi Jenn -

THanks for jumping in on this one. I have tried all of those in about every combination you can think of. Presently, my layer looks like this
     <esri:FeatureLayer ID="AllAvailableFeatureLayer" 
      Url="http://gismaps.pagnet.org/ArcGIS/rest/services/testprojectALLBikeCounts/FeatureServer/0"
      Renderer="{StaticResource AllRenderer}"
      MouseLeftButtonUp="AllAvailableFeatureLayer_MouseLeftButtonUp"
      SelectionColor="Yellow"
      OutFields="Location,VolunteerAM,PhoneAM,EmailAM,SpanishAM,VolunteerPM,PhonePM,EmailPM,SpanishPM"
      DisableClientCaching="True"
      Where="VolunteerAM = 'Available' and VolunteerPM = 'Available'"
      AutoSave="True">
            <esri:FeatureLayer.MapTip>
       <Border CornerRadius="10" BorderBrush="SaddleBrown" BorderThickness="3" Margin="0,0,15,15" Background="LightGray">
                        <StackPanel Margin="7">
         <StackPanel Orientation="Horizontal">
          <TextBlock Text="Location: " Foreground="Black" FontWeight="Bold"/>
          <TextBlock Text="{Binding [Location]}" Foreground="Black" />
         </StackPanel>
        </StackPanel>
       </Border>
      </esri:FeatureLayer.MapTip>
     </esri:FeatureLayer>

Note AutoSave is true. The code behind that I think should work looks like this
private void MyFeatureDataForm_EditEnded(object sender, EventArgs e)
   {   
   foreach (Layer lyr in MyMap.Layers)
    {
    if (lyr is FeatureLayer)
     {
     FeatureLayer featureLayer = lyr as FeatureLayer;
     featureLayer.Update();
     }
    }      
   }

However, with this code the save does not even work. If I comment out the Update(), the save DOES work. Strange right? As I thought about this over the weekend I wondered if maybe the save is working but the Update() is somehow causing a second save and restoring the original data from a cache somewhere. Could that be possible?
0 Kudos
JenniferNery
Esri Regular Contributor
FeatureDataForm's EditEnded event fires before FeatureLayer's EndSaveEdits.

The changes made in the layer need to be pushed to the server before you can re-query the service. You can call Update() in EndSaveEdits eventhandler but also know that any change on the layer cause your application to re-query the service which is expensive. You can maybe use a boolean to flag whether the attribute that was changed need to call update.
0 Kudos
DonFreeman
Emerging Contributor
Jenn -

Thanks so much. That solves my problem.
I am finding it somewhat frustrating to "discover" the order in which things execute. Is there a white paper or something somewhere where I could have discovered this myself?

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
You can go through the API's Library Reference http://help.arcgis.com/en/webapi/silverlight/apiref/webtoc.html# and go through the samples. I'll ask around if we have other online documentation that can help you see order of events or general workflow.
0 Kudos