OldValues and NewValues collections are empty

D

Doug Kent

When my FormView uses its ObjectDataSource to save changes, in the FormView's
ItemUpdating handler, the FormViewUpdateEventArgs OldValues and NewValues
collections are both completely empty.

The FormView is bound to an ObjectDataSource. The
ObjectDataSource has DataObjectTypeName, OldValuesParameterFormatString
and ConflictDetection set as shown below:

<asp:ObjectDataSource ID="ListingsDataSource" runat="server"
TypeName="Listing"
SelectMethod="GetListingWithAgent"
UpdateMethod="Update"
DataObjectTypeName ="Listing"
OldValuesParameterFormatString ="oldEntity"
ConflictDetection ="CompareAllValues"<selectparameters>
<asp:QueryStringParameter QueryStringField="lid"
Type="Int32" Direction="Input" Name="Listing_ID" />
<asp:QueryStringParameter QueryStringField="ts"
Type="String" Direction="Input" Name="timeStampEncoded" />
</selectparameters>
</asp:ObjectDataSource>

The FormView DefaultMode is "Edit", the bound controls in the EditTemplate
are populated by the FormView no problem (using "Bind"). No problem with
selecting.

The FormView looks like this:


<asp:FormView ID="ListingFormView" runat="server"
DataSourceID="ListingsDataSource"
DataKeyNames="ID,Timestamp"
DefaultMode="Edit"
AllowPaging="false">


Anyone have a clue what could be causing this behavior? Thanks!
 
S

Stan

When my FormView uses its ObjectDataSource to save changes, in the FormView's
ItemUpdating handler, the FormViewUpdateEventArgs OldValues and NewValues
collections are both completely empty.

The FormView is bound to an ObjectDataSource. The
ObjectDataSource has DataObjectTypeName, OldValuesParameterFormatString
and ConflictDetection set as shown below:

<asp:ObjectDataSource ID="ListingsDataSource" runat="server"
TypeName="Listing"
SelectMethod="GetListingWithAgent"
UpdateMethod="Update"
DataObjectTypeName ="Listing"
OldValuesParameterFormatString ="oldEntity"
ConflictDetection ="CompareAllValues"

<selectparameters>
<asp:QueryStringParameter QueryStringField="lid"
Type="Int32" Direction="Input" Name="Listing_ID" />
<asp:QueryStringParameter QueryStringField="ts"
Type="String" Direction="Input" Name="timeStampEncoded" />
</selectparameters>
</asp:ObjectDataSource>

The FormView DefaultMode is "Edit", the bound controls in the EditTemplate
are populated by the FormView no problem (using "Bind"). No problem with
selecting.

The FormView looks like this:

<asp:FormView ID="ListingFormView" runat="server"
DataSourceID="ListingsDataSource"
DataKeyNames="ID,Timestamp"
DefaultMode="Edit"
AllowPaging="false">

Anyone have a clue what could be causing this behavior? Thanks!

I don't know whether this will solve your problem but I have found
that when using ObjectDataSource as the source for FormView etc it
helps if the data returned by the Select method is a table belonging
to a typed dataset. These are created by adding a DataSet file (.xsd
file) to the App_Code folder. By default the designer will launch a
wizard for creating TableAdapters but this can be cancelled if the
actual data isn't from an SQL source. With the DataSet window open in
the designer, DataTables can be created with the required structure.
If you then create a class file for retrieving and handling the raw
data, create a Select method that returns a table of the named type.
Bind this to the ObjectDataSource. Then when setting up the FormView
you will find that it behaves much like one that is attached to a
SqlDataSource.

HTH
 
D

Doug Kent

Thanks for the suggestion.

I don't think this has to do with using an ObjectDataSource. I find that
using a LinqDataSource instead has no effect on the problem. I believe the
problem is with the FormView, and that we might be closer to the answer if we
could understand why, in the FormView's ItemUpdating handler, the
FormViewUpdateEventArgs OldValues and NewValues collections are both
completely empty.
 
D

Doug Kent

Clue?

I have found that a DetailsView, using BoundField Fields, works fine using
the exact same ObjectDataSource where the FormView, with its EditTemplate,
fails.
 
D

Doug Kent

I have been able to get the code to work with a simple change, though I can't
explain why the change makes a difference.

This piece of code works:

1 <asp:FormView ID="ListingFormViewTest" runat="server"
2 DataSourceID="ListingsDataSource"
3 DataKeyNames="ID,TimeStamp"
4 DefaultMode="Edit"
5 AllowPaging="false">
6 <EditItemTemplate>
7 <asp:Button ID="Save" runat="server" Text="Save"
CommandName="Update" />
8 <table>
9 <tr>
10 <td><asp:TextBox ID="ParcelIDTextBox" runat="server"
Text='<%# Bind("Parcel_ID") %>' /></td>
11 </tr>
12 </table>
13 </EditItemTemplate>
14 </asp:FormView>
15

While this piece of code does not work:

1 <asp:FormView ID="ListingFormViewTest" runat="server"
2 DataSourceID="ListingsDataSource"
3 DataKeyNames="ID,TimeStamp"
4 DefaultMode="Edit"
5 AllowPaging="false">
6 <EditItemTemplate>
7 <asp:Button ID="Save" runat="server" Text="Save"
CommandName="Update" />
8 <table runat="server" id="ATable">
9 <tr>
10 <td><asp:TextBox ID="ParcelIDTextBox"
runat="server" Text='<%# Bind("Parcel_ID") %>' /></td>
11 </tr>
12 </table>
13 </EditItemTemplate>
14 </asp:FormView>
15

The difference is on line 8. In the non-working example, the table element
contains "runat=server".

Why this would make a difference is a head scratcher to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top