Update method always gets old values from a form view
Update method always gets old values from a form view
am 10.04.2008 21:01:15 von Beach Runner
Hi,
I have an object data source attached to a form view. The data source calls
bll's update method. I can't figure out why the bll's update method never
gets updated fields - it always gets original values. I made sure that
fields are two-way bound in the form's . I don't get any
runtime errors. I set a breakpoint in the update method and can clearly see
that old values are passed to it.
My bll's update method is declared as follows:
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool UpdateItem(int itemID, DateTime startDate, DateTime endDate,
string content);
The form view:
DataSourceID="itemDataSource">
Start Date:
End Date:
Content:
CausesValidation="True" CommandName="Update"
Text="Update">
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
[...]
[...]
DeleteMethod="DeleteItem"
InsertMethod="AddItem" OldValuesParameterFormatString="{0}"
TypeName="ItemsBLL" UpdateMethod="UpdateItem"
SelectMethod="GetItemByItemID" >
[...]
I'd appreciate any help/pointers because I'm stuck at this point.
Thanks,
Bob.
Re: Update method always gets old values from a form view
am 11.04.2008 10:13:00 von wisccal
Hi Bob,
I can't reproduce your problem. How do you determine the the ID of the
record to update? Here is my example that works just fine on my
machine:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
Default.aspx.cs:
using System;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
}
public class ItemsBLL {
private static System.Collections.Generic.List- items =
new System.Collections.Generic.List- () {
new Item {ItemID = 1, StartDate = new DateTime(2007,5,3),
EndDate = new DateTime(2007,11,12), Content="Great News"},
new Item {ItemID = 2, StartDate = new DateTime(2008,1,1),
EndDate = new DateTime(2008,1,31), Content="Bad News"},
new Item {ItemID = 4, StartDate = new DateTime(1999,7,4),
EndDate = DateTime.Now, Content="Not Sure"}
};
[System.ComponentModel.DataObjectMethod(System.ComponentMode l.DataObjectMethodType.Select,
true)]
public Item GetItemByItemID(int itemID)
{
var its = items.Where(i => i.ItemID == itemID);
if(its.Count() > 0) {
return its.First();
}
return null;
}
[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool UpdateItem(int itemID, DateTime startDate,
DateTime endDate, string content) {
var its = items.Where(i => i.ItemID == itemID);
if(its.Count() > 0) {
Item it = its.First();
it.StartDate = startDate;
it.EndDate = endDate;
it.Content = content;
return true;
}
return false;
}
}
public class Item {
public int ItemID {
get;set;
}
public DateTime StartDate {
get;set;
}
public DateTime EndDate {
get;set;
}
public string Content {
get;set;
}
}
}
===========
Regards,
Steve
www.stkomp.com
bob wrote:
> Hi,
>
> I have an object data source attached to a form view. The data source calls
> bll's update method. I can't figure out why the bll's update method never
> gets updated fields - it always gets original values. I made sure that
> fields are two-way bound in the form's . I don't get any
> runtime errors. I set a breakpoint in the update method and can clearly see
> that old values are passed to it.
>
> My bll's update method is declared as follows:
>
> [System.ComponentModel.DataObjectMethodAttribute
> (System.ComponentModel.DataObjectMethodType.Update, true)]
> public bool UpdateItem(int itemID, DateTime startDate, DateTime endDate,
> string content);
>
> The form view:
>
>
> DataSourceID="itemDataSource">
>
> Start Date:
>
> End Date:
>
> Content:
>
>
> CausesValidation="True" CommandName="Update"
> Text="Update">
>
> CausesValidation="False" CommandName="Cancel"
> Text="Cancel">
>
>
> [...]
>
>
> [...]
>
>
>
> DeleteMethod="DeleteItem"
> InsertMethod="AddItem" OldValuesParameterFormatString="{0}"
> TypeName="ItemsBLL" UpdateMethod="UpdateItem"
> SelectMethod="GetItemByItemID" >
>
>
>
>
>
> [...]
>
>
>
> I'd appreciate any help/pointers because I'm stuck at this point.
>
> Thanks,
> Bob.
Re: Update method always gets old values from a form view
am 11.04.2008 15:09:39 von Beach Runner
Thanks for the reply. The ItemID is read from another control which is a
dropdownlist.
I have created similar pages with the same BLL in the past and had no
problems. I just created a replacement page that is almost identical to the
one I had problems with and it works as expected. I could use the new page
instead but it bothers me that I can't figure out why the original did not
work. In insert mode all parameters passed to BLL were null or
uninitialized and in update mode old values were passed.
I wasted a whole day trying to debug it. I'm afraid that something like
that can happen on the deployment machine. The problem is that I do not
know what else to do in order to debug it. It almost looks like the
framework is generating (or using from a cache) code that I do not expect.
Any hints on how to debug it? Although I have another page working well
(and doing what the original was supposed to) I'm still holding on to the
original hoping to find out what the problem is.
Thanks
wrote in message
news:9a4c9efd-fb6c-4682-9fbe-d52bed70601b@a1g2000hsb.googleg roups.com...
> Hi Bob,
>
> I can't reproduce your problem. How do you determine the the ID of the
> record to update? Here is my example that works just fine on my
> machine:
>
>
> Default.aspx:
>
> <%@ Page Language="C#" AutoEventWireup="true"
> CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
>
>
>
>
>
>
>
>
>
>
> Default.aspx.cs:
>
> using System;
> using System.Linq;
> using System.Data.Linq;
> using System.Web;
> using System.Web.UI;
>
> namespace WebApplication2
> {
> public partial class _Default : System.Web.UI.Page
> {
> }
>
> public class ItemsBLL {
> private static System.Collections.Generic.List- items =
> new System.Collections.Generic.List- () {
> new Item {ItemID = 1, StartDate = new DateTime(2007,5,3),
> EndDate = new DateTime(2007,11,12), Content="Great News"},
> new Item {ItemID = 2, StartDate = new DateTime(2008,1,1),
> EndDate = new DateTime(2008,1,31), Content="Bad News"},
> new Item {ItemID = 4, StartDate = new DateTime(1999,7,4),
> EndDate = DateTime.Now, Content="Not Sure"}
> };
>
>
> [System.ComponentModel.DataObjectMethod(System.ComponentMode l.DataObjectMethodType.Select,
> true)]
> public Item GetItemByItemID(int itemID)
> {
> var its = items.Where(i => i.ItemID == itemID);
> if(its.Count() > 0) {
> return its.First();
> }
> return null;
> }
>
> [System.ComponentModel.DataObjectMethodAttribute
> (System.ComponentModel.DataObjectMethodType.Update, true)]
> public bool UpdateItem(int itemID, DateTime startDate,
> DateTime endDate, string content) {
> var its = items.Where(i => i.ItemID == itemID);
> if(its.Count() > 0) {
> Item it = its.First();
> it.StartDate = startDate;
> it.EndDate = endDate;
> it.Content = content;
> return true;
> }
> return false;
> }
> }
> public class Item {
> public int ItemID {
> get;set;
> }
> public DateTime StartDate {
> get;set;
> }
> public DateTime EndDate {
> get;set;
> }
> public string Content {
> get;set;
> }
> }
> }
>
>
> ===========
> Regards,
> Steve
> www.stkomp.com
>
> bob wrote:
>> Hi,
>>
>> I have an object data source attached to a form view. The data source
>> calls
>> bll's update method. I can't figure out why the bll's update method
>> never
>> gets updated fields - it always gets original values. I made sure that
>> fields are two-way bound in the form's . I don't get
>> any
>> runtime errors. I set a breakpoint in the update method and can clearly
>> see
>> that old values are passed to it.
>>
>> My bll's update method is declared as follows:
>>
>> [System.ComponentModel.DataObjectMethodAttribute
>> (System.ComponentModel.DataObjectMethodType.Update, true)]
>> public bool UpdateItem(int itemID, DateTime startDate, DateTime
>> endDate,
>> string content);
>>
>> The form view:
>>
>>
>> DataSourceID="itemDataSource">
>>
>> Start Date:
>>
>> End Date:
>>
>> Content:
>>
>>
>> CausesValidation="True" CommandName="Update"
>> Text="Update">
>>
>> CausesValidation="False" CommandName="Cancel"
>> Text="Cancel">
>>
>>
>> [...]
>>
>>
>> [...]
>>
>>
>>
>> DeleteMethod="DeleteItem"
>> InsertMethod="AddItem" OldValuesParameterFormatString="{0}"
>> TypeName="ItemsBLL" UpdateMethod="UpdateItem"
>> SelectMethod="GetItemByItemID" >
>>
>>
>>
>>
>>
>> [...]
>>
>>
>>
>> I'd appreciate any help/pointers because I'm stuck at this point.
>>
>> Thanks,
>> Bob.
Re: Update method always gets old values from a form view
am 11.04.2008 15:47:49 von wisccal
Hi Bob,
Without seeing your code, it's not that easy to pinpoint the problem.
You're saying you created an identical page. So what is
different between the two pages? If codebehind is exactly the same,
then the problem is most likely the web page file.
Also, I would try and hook into the different events of the
ObjectDataSource control like OnObjectCreated, OnDataBinding, etc. An
example would be:
in your aspx file:
OnObjectCreated="itemDataSource_ObjectCreated" ...>
in the codebehind:
protected void itemDataSource_ObjectCreated(object s,
ObjectDataSourceEventArgs e)
{
///...test your objects. E.g. what is the value of
e.ObjectInstance, of your controls?
}
HTH.
==========
Regards,
Steve
www.stkomp.com
bob wrote:
> Thanks for the reply. The ItemID is read from another control which is a
> dropdownlist.
>
> I have created similar pages with the same BLL in the past and had no
> problems. I just created a replacement page that is almost identical to the
> one I had problems with and it works as expected. I could use the new page
> instead but it bothers me that I can't figure out why the original did not
> work. In insert mode all parameters passed to BLL were null or
> uninitialized and in update mode old values were passed.
> I wasted a whole day trying to debug it. I'm afraid that something like
> that can happen on the deployment machine. The problem is that I do not
> know what else to do in order to debug it. It almost looks like the
> framework is generating (or using from a cache) code that I do not expect.
>
> Any hints on how to debug it? Although I have another page working well
> (and doing what the original was supposed to) I'm still holding on to the
> original hoping to find out what the problem is.
>
> Thanks
>
> wrote in message
> news:9a4c9efd-fb6c-4682-9fbe-d52bed70601b@a1g2000hsb.googleg roups.com...
> > Hi Bob,
> >
> > I can't reproduce your problem. How do you determine the the ID of the
> > record to update? Here is my example that works just fine on my
> > machine:
> >
> >
> > Default.aspx:
> >
> > <%@ Page Language="C#" AutoEventWireup="true"
> > CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Default.aspx.cs:
> >
> > using System;
> > using System.Linq;
> > using System.Data.Linq;
> > using System.Web;
> > using System.Web.UI;
> >
> > namespace WebApplication2
> > {
> > public partial class _Default : System.Web.UI.Page
> > {
> > }
> >
> > public class ItemsBLL {
> > private static System.Collections.Generic.List- items =
> > new System.Collections.Generic.List- () {
> > new Item {ItemID = 1, StartDate = new DateTime(2007,5,3),
> > EndDate = new DateTime(2007,11,12), Content="Great News"},
> > new Item {ItemID = 2, StartDate = new DateTime(2008,1,1),
> > EndDate = new DateTime(2008,1,31), Content="Bad News"},
> > new Item {ItemID = 4, StartDate = new DateTime(1999,7,4),
> > EndDate = DateTime.Now, Content="Not Sure"}
> > };
> >
> >
> > [System.ComponentModel.DataObjectMethod(System.ComponentMode l.DataObjectMethodType.Select,
> > true)]
> > public Item GetItemByItemID(int itemID)
> > {
> > var its = items.Where(i => i.ItemID == itemID);
> > if(its.Count() > 0) {
> > return its.First();
> > }
> > return null;
> > }
> >
> > [System.ComponentModel.DataObjectMethodAttribute
> > (System.ComponentModel.DataObjectMethodType.Update, true)]
> > public bool UpdateItem(int itemID, DateTime startDate,
> > DateTime endDate, string content) {
> > var its = items.Where(i => i.ItemID == itemID);
> > if(its.Count() > 0) {
> > Item it = its.First();
> > it.StartDate = startDate;
> > it.EndDate = endDate;
> > it.Content = content;
> > return true;
> > }
> > return false;
> > }
> > }
> > public class Item {
> > public int ItemID {
> > get;set;
> > }
> > public DateTime StartDate {
> > get;set;
> > }
> > public DateTime EndDate {
> > get;set;
> > }
> > public string Content {
> > get;set;
> > }
> > }
> > }
> >
> >
> > ===========
> > Regards,
> > Steve
> > www.stkomp.com
> >
> > bob wrote:
> >> Hi,
> >>
> >> I have an object data source attached to a form view. The data source
> >> calls
> >> bll's update method. I can't figure out why the bll's update method
> >> never
> >> gets updated fields - it always gets original values. I made sure that
> >> fields are two-way bound in the form's . I don't get
> >> any
> >> runtime errors. I set a breakpoint in the update method and can clearly
> >> see
> >> that old values are passed to it.
> >>
> >> My bll's update method is declared as follows:
> >>
> >> [System.ComponentModel.DataObjectMethodAttribute
> >> (System.ComponentModel.DataObjectMethodType.Update, true)]
> >> public bool UpdateItem(int itemID, DateTime startDate, DateTime
> >> endDate,
> >> string content);
> >>
> >> The form view:
> >>
> >>
> >> DataSourceID="itemDataSource">
> >>
> >> Start Date:
> >>
> >> End Date:
> >>
> >> Content:
> >>
> >>
> >> CausesValidation="True" CommandName="Update"
> >> Text="Update">
> >>
> >> CausesValidation="False" CommandName="Cancel"
> >> Text="Cancel">
> >>
> >>
> >> [...]
> >>
> >>
> >> [...]
> >>
> >>
> >>
> >> DeleteMethod="DeleteItem"
> >> InsertMethod="AddItem" OldValuesParameterFormatString="{0}"
> >> TypeName="ItemsBLL" UpdateMethod="UpdateItem"
> >> SelectMethod="GetItemByItemID" >
> >>
> >>
> >>
> >>
> >>
> >> [...]
> >>
> >>
> >>
> >> I'd appreciate any help/pointers because I'm stuck at this point.
> >>
> >> Thanks,
> >> Bob.
Re: Update method always gets old values from a form view
am 11.04.2008 16:47:20 von Beach Runner
Steve,
Thanks for your help. I managed to find the problem. Thanks for bringing
up "". I [reluctantly] went back to the problematic code and looked
for differences. I found a single line in code-behind that called
DataBind() on the form view. The call took place in Page_Load() on post
back. It all makes sense now. By binding the form view I was [implicitly]
restoring original values and initializing new ones with empty/null before
the BLL's methods were called by the framework.
I spend a lot of time looking into BLL, aspx page, and other event handlers
and ignoring the simplest one which was Page_Load(). I think I learned my
lesson.
Thanks,
Bob
wrote in message
news:a7737018-58e7-4de1-92e7-607bf1cc07f6@b1g2000hsg.googleg roups.com...
> Hi Bob,
>
> Without seeing your code, it's not that easy to pinpoint the problem.
> You're saying you created an identical page. So what is
> different between the two pages? If codebehind is exactly the same,
> then the problem is most likely the web page file.
>
> Also, I would try and hook into the different events of the
> ObjectDataSource control like OnObjectCreated, OnDataBinding, etc. An
> example would be:
>
> in your aspx file:
>
> OnObjectCreated="itemDataSource_ObjectCreated" ...>
>
> in the codebehind:
> protected void itemDataSource_ObjectCreated(object s,
> ObjectDataSourceEventArgs e)
> {
> ///...test your objects. E.g. what is the value of
> e.ObjectInstance, of your controls?
> }
>
> HTH.
>
> ==========
> Regards,
> Steve
> www.stkomp.com
>
> bob wrote:
>> Thanks for the reply. The ItemID is read from another control which is a
>> dropdownlist.
>>
>> I have created similar pages with the same BLL in the past and had no
>> problems. I just created a replacement page that is almost identical to
>> the
>> one I had problems with and it works as expected. I could use the new
>> page
>> instead but it bothers me that I can't figure out why the original did
>> not
>> work. In insert mode all parameters passed to BLL were null or
>> uninitialized and in update mode old values were passed.
>> I wasted a whole day trying to debug it. I'm afraid that something like
>> that can happen on the deployment machine. The problem is that I do not
>> know what else to do in order to debug it. It almost looks like the
>> framework is generating (or using from a cache) code that I do not
>> expect.
>>
>> Any hints on how to debug it? Although I have another page working well
>> (and doing what the original was supposed to) I'm still holding on to the
>> original hoping to find out what the problem is.
>>
>> Thanks
>>
>> wrote in message
>> news:9a4c9efd-fb6c-4682-9fbe-d52bed70601b@a1g2000hsb.googleg roups.com...
>> > Hi Bob,
>> >
>> > I can't reproduce your problem. How do you determine the the ID of the
>> > record to update? Here is my example that works just fine on my
>> > machine:
>> >
>> >
>> > Default.aspx:
>> >
>> > <%@ Page Language="C#" AutoEventWireup="true"
>> > CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > Default.aspx.cs:
>> >
>> > using System;
>> > using System.Linq;
>> > using System.Data.Linq;
>> > using System.Web;
>> > using System.Web.UI;
>> >
>> > namespace WebApplication2
>> > {
>> > public partial class _Default : System.Web.UI.Page
>> > {
>> > }
>> >
>> > public class ItemsBLL {
>> > private static System.Collections.Generic.List- items =
>> > new System.Collections.Generic.List- () {
>> > new Item {ItemID = 1, StartDate = new DateTime(2007,5,3),
>> > EndDate = new DateTime(2007,11,12), Content="Great News"},
>> > new Item {ItemID = 2, StartDate = new DateTime(2008,1,1),
>> > EndDate = new DateTime(2008,1,31), Content="Bad News"},
>> > new Item {ItemID = 4, StartDate = new DateTime(1999,7,4),
>> > EndDate = DateTime.Now, Content="Not Sure"}
>> > };
>> >
>> >
>> > [System.ComponentModel.DataObjectMethod(System.ComponentMode l.DataObjectMethodType.Select,
>> > true)]
>> > public Item GetItemByItemID(int itemID)
>> > {
>> > var its = items.Where(i => i.ItemID == itemID);
>> > if(its.Count() > 0) {
>> > return its.First();
>> > }
>> > return null;
>> > }
>> >
>> > [System.ComponentModel.DataObjectMethodAttribute
>> > (System.ComponentModel.DataObjectMethodType.Update, true)]
>> > public bool UpdateItem(int itemID, DateTime startDate,
>> > DateTime endDate, string content) {
>> > var its = items.Where(i => i.ItemID == itemID);
>> > if(its.Count() > 0) {
>> > Item it = its.First();
>> > it.StartDate = startDate;
>> > it.EndDate = endDate;
>> > it.Content = content;
>> > return true;
>> > }
>> > return false;
>> > }
>> > }
>> > public class Item {
>> > public int ItemID {
>> > get;set;
>> > }
>> > public DateTime StartDate {
>> > get;set;
>> > }
>> > public DateTime EndDate {
>> > get;set;
>> > }
>> > public string Content {
>> > get;set;
>> > }
>> > }
>> > }
>> >
>> >
>> > ===========
>> > Regards,
>> > Steve
>> > www.stkomp.com
>> >
>> > bob wrote:
>> >> Hi,
>> >>
>> >> I have an object data source attached to a form view. The data source
>> >> calls
>> >> bll's update method. I can't figure out why the bll's update method
>> >> never
>> >> gets updated fields - it always gets original values. I made sure
>> >> that
>> >> fields are two-way bound in the form's . I don't
>> >> get
>> >> any
>> >> runtime errors. I set a breakpoint in the update method and can
>> >> clearly
>> >> see
>> >> that old values are passed to it.
>> >>
>> >> My bll's update method is declared as follows:
>> >>
>> >> [System.ComponentModel.DataObjectMethodAttribute
>> >> (System.ComponentModel.DataObjectMethodType.Update, true)]
>> >> public bool UpdateItem(int itemID, DateTime startDate, DateTime
>> >> endDate,
>> >> string content);
>> >>
>> >> The form view:
>> >>
>> >>
>> >> DataSourceID="itemDataSource">
>> >>
>> >> Start Date:
>> >>
>> >> End Date:
>> >>
>> >> Content:
>> >>
>> >>
>> >> CausesValidation="True" CommandName="Update"
>> >> Text="Update">
>> >>
>> >> CausesValidation="False" CommandName="Cancel"
>> >> Text="Cancel">
>> >>
>> >>
>> >> [...]
>> >>
>> >>
>> >> [...]
>> >>
>> >>
>> >>
>> >> DeleteMethod="DeleteItem"
>> >> InsertMethod="AddItem" OldValuesParameterFormatString="{0}"
>> >> TypeName="ItemsBLL" UpdateMethod="UpdateItem"
>> >> SelectMethod="GetItemByItemID" >
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> [...]
>> >>
>> >>
>> >>
>> >> I'd appreciate any help/pointers because I'm stuck at this point.
>> >>
>> >> Thanks,
>> >> Bob.