OldValues and NewValues collections are empty

Discussion in 'ASP .Net Web Controls' started by Doug Kent, Jul 30, 2008.

  1. Doug Kent

    Doug Kent Guest

    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!
    Doug Kent, Jul 30, 2008
    #1
    1. Advertising

  2. Doug Kent

    Stan Guest

    On 30 Jul, 02:16, Doug Kent <>
    wrote:
    > 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
    Stan, Jul 30, 2008
    #2
    1. Advertising

  3. Doug Kent

    Doug Kent Guest

    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.
    Doug Kent, Jul 30, 2008
    #3
  4. Doug Kent

    Doug Kent Guest

    Clue?

    I have found that a DetailsView, using BoundField Fields, works fine using
    the exact same ObjectDataSource where the FormView, with its EditTemplate,
    fails.
    Doug Kent, Jul 31, 2008
    #4
  5. Doug Kent

    Doug Kent Guest

    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.
    Doug Kent, Jul 31, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Olbert

    GridView: Empty OldValues, NewValues

    Mark Olbert, Jan 19, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    12,327
    jfortier2
    Jul 22, 2006
  2. LamSoft
    Replies:
    0
    Views:
    359
    LamSoft
    Jul 5, 2007
  3. rahulsurya
    Replies:
    0
    Views:
    492
    rahulsurya
    Dec 12, 2007
  4. Marius Manolea
    Replies:
    0
    Views:
    1,006
    Marius Manolea
    Jun 4, 2008
  5. Doug Kent

    OldValues and NewValues collections are empty

    Doug Kent, Jul 30, 2008, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    164
    Doug Kent
    Jul 30, 2008
Loading...

Share This Page