|
|
|
start date: Tue, 21 Aug 2007 09:28:07 -0400,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
TarTar
|
|
2
Cowboy \(Gregory A. Beamer\) oSpamM
|
|
3
TarTar
|
|
4
Steve
|
Select method of ObjectDataSource called twice - second post
Hello,
I have already posted this problem, but I have not received any response
yet. I will try to describe it again.
We have a list control (e.g. DataList) and an ObjectDataSource on an ASP.NET
web page. When we open the page the Select method (here: GetCustomers) is
called twice. Why? It is obvious performance hit as the data needs to be
retrieved twice. How to avoid the duplicated calls?
Below there is complete code for both the ASP.NET page and its code-behind:
<asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource"
runat="server">
<ItemTemplate>
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectDataSource ID="CustomerDataSource" SelectMethod="GetCustomers"
TypeName="Customers" runat="server" />
public class Customers
{
public List<Customer> GetCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customer> list = new List<Customer>();
list.Add(test);
return list;
}
}
public class Customer
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
Thanks,
Leszek
Date:Tue, 21 Aug 2007 09:28:07 -0400
Author:
|
Re: Select method of ObjectDataSource called twice - second post
It does not look like you posted the actual code behind for the page here,
or is that an empty file? I see nothing wrong with the class file or the
ASP.NET tagged portion.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box!
|
*************************************************
"TarTar" wrote in message
news:%23W9Cpc$4HHA.6024@TK2MSFTNGP05.phx.gbl...
> Hello,
>
> I have already posted this problem, but I have not received any response
> yet. I will try to describe it again.
>
> We have a list control (e.g. DataList) and an ObjectDataSource on an
> ASP.NET web page. When we open the page the Select method (here:
> GetCustomers) is called twice. Why? It is obvious performance hit as the
> data needs to be retrieved twice. How to avoid the duplicated calls?
>
> Below there is complete code for both the ASP.NET page and its
> code-behind:
>
> <asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource"
> runat="server">
> <ItemTemplate>
> Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
> runat="server"/>
> </ItemTemplate>
> </asp:DataList>
> <asp:ObjectDataSource ID="CustomerDataSource" SelectMethod="GetCustomers"
> TypeName="Customers" runat="server" />
>
> public class Customers
> {
> public List<Customer> GetCustomers()
> {
> Customer test = new Customer();
> test.Name = "Uakari Mabuto";
> List<Customer> list = new List<Customer>();
> list.Add(test);
> return list;
> }
> }
> public class Customer
> {
> private string name;
> public string Name
> {
> get { return name; }
> set { name = value; }
> }
> }
>
>
> Thanks,
> Leszek
>
>
>
Date:Tue, 21 Aug 2007 09:10:58 -0500
Author:
|
Re: Select method of ObjectDataSource called twice - second post
It sounds like the databinding is being called twice. Check your
Page_Load event to see if you're doing something like calling
Page.DataBind(), then DataList1.DataBind().
You also could have something in the Page_Load that causes it to re-load
the current page??
Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
TarTar wrote:
> Hello,
>
> I have already posted this problem, but I have not received any response
> yet. I will try to describe it again.
>
> We have a list control (e.g. DataList) and an ObjectDataSource on an ASP.NET
> web page. When we open the page the Select method (here: GetCustomers) is
> called twice. Why? It is obvious performance hit as the data needs to be
> retrieved twice. How to avoid the duplicated calls?
>
> Below there is complete code for both the ASP.NET page and its code-behind:
>
> <asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource"
> runat="server">
> <ItemTemplate>
> Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
> runat="server"/>
> </ItemTemplate>
> </asp:DataList>
> <asp:ObjectDataSource ID="CustomerDataSource" SelectMethod="GetCustomers"
> TypeName="Customers" runat="server" />
>
> public class Customers
> {
> public List<Customer> GetCustomers()
> {
> Customer test = new Customer();
> test.Name = "Uakari Mabuto";
> List<Customer> list = new List<Customer>();
> list.Add(test);
> return list;
> }
> }
> public class Customer
> {
> private string name;
> public string Name
> {
> get { return name; }
> set { name = value; }
> }
> }
>
>
> Thanks,
> Leszek
>
>
>
Date:Tue, 21 Aug 2007 10:10:58 -0400
Author:
|
Re: Select method of ObjectDataSource called twice - second post
Thanks Steve and Cowboy for the answers.
I agree - the ASP.NET code and C# code looks fine. There is also no code in
Page_Load. Yet, the GetCustomers() method is called twice when the page is
called first time. It looks like a built-in feature of ObjectDataSource (or
the DataList control?).
Whay is that? The code is very rudimentary - no parameters, no code in
Page_Load or any other event handler.
Thanks,
Leszek
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:O0sJb0$4HHA.5164@TK2MSFTNGP05.phx.gbl...
> It does not look like you posted the actual code behind for the page here,
> or is that an empty file? I see nothing wrong with the class file or the
> ASP.NET tagged portion.
>
> --
> Gregory A. Beamer
> MVP, MCP: +I, SE, SD, DBA
>
> *************************************************
> | Think outside the box! |
> *************************************************
> "TarTar" wrote in message
> news:%23W9Cpc$4HHA.6024@TK2MSFTNGP05.phx.gbl...
>> Hello,
>>
>> I have already posted this problem, but I have not received any response
>> yet. I will try to describe it again.
>>
>> We have a list control (e.g. DataList) and an ObjectDataSource on an
>> ASP.NET web page. When we open the page the Select method (here:
>> GetCustomers) is called twice. Why? It is obvious performance hit as the
>> data needs to be retrieved twice. How to avoid the duplicated calls?
>>
>> Below there is complete code for both the ASP.NET page and its
>> code-behind:
>>
>> <asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource"
>> runat="server">
>> <ItemTemplate>
>> Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
>> runat="server"/>
>> </ItemTemplate>
>> </asp:DataList>
>> <asp:ObjectDataSource ID="CustomerDataSource" SelectMethod="GetCustomers"
>> TypeName="Customers" runat="server" />
>>
>> public class Customers
>> {
>> public List<Customer> GetCustomers()
>> {
>> Customer test = new Customer();
>> test.Name = "Uakari Mabuto";
>> List<Customer> list = new List<Customer>();
>> list.Add(test);
>> return list;
>> }
>> }
>> public class Customer
>> {
>> private string name;
>> public string Name
>> {
>> get { return name; }
>> set { name = value; }
>> }
>> }
>>
>>
>> Thanks,
>> Leszek
>>
>>
>>
>
>
Date:Tue, 21 Aug 2007 10:34:18 -0400
Author:
|
|
|