SL 3.8.2 Object.Save fails in the InvokeMethod

SL 3.8.2 Object.Save fails in the InvokeMethod

Old forum URL: forums.lhotka.net/forums/t/8450.aspx


Jav posted on Monday, February 01, 2010

This is my first attempt to try and save an object graph to the DB. The code in MainPage.xaml is:

Button x:Name="cmdSubmit"
Content="Submit"
Csla:InvokeMethod.MethodName="Save"
Csla:InvokeMethod.TriggerEvent="Click" />

The object is a BusinessBase object.
The execution stops in the CallMethod method of InvokeMethod class on line 3. The target looks like a perfectly sound parent object, and the methodName is Save, but the targetMethod comes back null with the following error:

System.MissingMethodException was unhandled by user code
Message="Save"
StackTrace:
at Csla.Silverlight.InvokeMethod.CallMethod(Object sender, EventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:

I do not have a Save Method in my object. But looking at the demos, it appears that it is not necessary.

Can't understand what is the problem.

Jav

triplea replied on Tuesday, February 02, 2010

Do you use a CslaDataProvider on your page? Also, you probably have to set the DataContext of the parent container to the provider.

Jav replied on Tuesday, February 02, 2010

Thanks for your help.

Yes I do use a CslaDataProvider, and I do have the DataContext on the page which is providing and acquiring data from the UI controls on the page. I also know that the properties on my objects are being properly set with the data. Now I am trying to save that info back to the DB.

As for the DataContext, I even tried placing my Submit button by itself in a Canvas and setting the DataContext of the Canvas but to no avail.

In fact in the Csla.Silverlight.InvokeMethod.CallMethod, both the target, i.e., the object that is to be saved and the MethodName are set properly. The problem comes on the next line when the code tries to find the 'MethodName' method on the 'target'.

Jav

Jav replied on Tuesday, February 02, 2010

I might have discovered what my problem was. The DataContext in the LayoutRoot of the page is:

DataContext="{Binding Source={StaticResource MyObjectData}, Path=Data}"

As I mentioned in the previous post, I did enclose the Submit button in a Canvas with its DataContext set, but I set it by simply copying and pasting the line above.

When I changed the Canvas DataContext to:

DataContext="{Binding Source={StaticResource MyObjectData}}"

without the Path, that error has disappeared and the code proceeds all the way to my DataPortal_xyz methods - of course it gets stuck there - but that's my problem.

Jav

slh4342 replied on Wednesday, March 10, 2010

I am having the same problem, but when I remove path=data, I lose the binding to my items

<Grid  x:Name="grdDates" DataContext="{Binding Source={StaticResource PQIProviderDetailAccess}}" >

<basics:DatePicker  Text="{Binding Path=CreateDate, Mode=TwoWay}" Grid.Row="2" Grid.Column="1" />
<basics:DatePicker  Text="{Binding OpenDate, Mode=TwoWay}"  Grid.Row="3" Grid.Column="1" />

<Button x:Name="SaveButton" Content="Save Dates" Width="100"
Grid.Row="22" Grid.Column="0" Grid.ColumnSpan="2"
csla:InvokeMethod.TriggerEvent="Click"
csla:InvokeMethod.MethodName="Save"/>

RockfordLhotka replied on Wednesday, March 10, 2010

The DataContext of your form overall needs to be the Data property of the data provider.

But the DataContext of InvokeMethod needs to be the data provider itself, since it is the data provider that implements the method you are trying to invoke.

Copyright (c) Marimer LLC