Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Select method of ObjectDataSource called twice - second post

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TarTar - 21 Aug 2007 14:28 GMT
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
Cowboy (Gregory A. Beamer) - 21 Aug 2007 15:10 GMT
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.

Signature

Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************

| Think outside the box!

*************************************************
> Hello,
>
[quoted text clipped - 42 lines]
> Thanks,
> Leszek
TarTar - 21 Aug 2007 15:34 GMT
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

> 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
[quoted text clipped - 48 lines]
>> Thanks,
>> Leszek
TarTar - 24 Aug 2007 19:58 GMT
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

> Thanks Steve and Cowboy for the answers.
>
[quoted text clipped - 61 lines]
>>> Thanks,
>>> Leszek
Steve - 21 Aug 2007 15:10 GMT
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

> Hello,
>
[quoted text clipped - 41 lines]
> Thanks,
> Leszek

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.