Select method of ObjectDataSource called twice - second post

T

TarTar

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
 
C

Cowboy \(Gregory A. Beamer\)

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.
 
S

Steve

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
 
T

TarTar

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
 
T

TarTar

Problem solved - but it is the weirdest quirk of ASP.NET (or Visual Studio
and its built-in web server) I have met so far.
It turned out the cause was not the ObjectDataSource or any event handler
but the filename. When I renamed the file from Default.aspx to
Homepage.aspx, calls are not duplicated any more.

Leszek
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top