473,763 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select method of ObjectDataSourc e 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 ObjectDataSourc e 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="CustomersLi st" DataSourceID="C ustomerDataSour ce"
runat="server">
<ItemTemplate >
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectData Source ID="CustomerDat aSource" SelectMethod="G etCustomers"
TypeName="Custo mers" runat="server" />

public class Customers
{
public List<CustomerGe tCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customerli st = 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

Aug 21 '07 #1
4 4702
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" <sp*******@love ly.spamwrote in message
news:%2******** ********@TK2MSF TNGP05.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 ObjectDataSourc e 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="CustomersLi st" DataSourceID="C ustomerDataSour ce"
runat="server">
<ItemTemplate >
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectData Source ID="CustomerDat aSource" SelectMethod="G etCustomers"
TypeName="Custo mers" runat="server" />

public class Customers
{
public List<CustomerGe tCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customerli st = 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

Aug 21 '07 #2
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.DataB ind().

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 ObjectDataSourc e 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="CustomersLi st" DataSourceID="C ustomerDataSour ce"
runat="server">
<ItemTemplate >
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="server"/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectData Source ID="CustomerDat aSource" SelectMethod="G etCustomers"
TypeName="Custo mers" runat="server" />

public class Customers
{
public List<CustomerGe tCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customerli st = 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
Aug 21 '07 #3
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 ObjectDataSourc e (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)" <No************ @comcast.netNoS pamMwrote in
message news:O0******** ******@TK2MSFTN GP05.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" <sp*******@love ly.spamwrote in message
news:%2******** ********@TK2MSF TNGP05.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 ObjectDataSourc e 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:DataLis t ID="CustomersLi st" DataSourceID="C ustomerDataSour ce"
runat="server" >
<ItemTemplate >
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="serve r"/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectDat aSource ID="CustomerDat aSource" SelectMethod="G etCustomers"
TypeName="Cust omers" runat="server" />

public class Customers
{
public List<CustomerGe tCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customerli st = 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


Aug 21 '07 #4
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 ObjectDataSourc e 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

"TarTar" <sp*******@love ly.spamwrote in message
news:O$******** ******@TK2MSFTN GP04.phx.gbl...
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 ObjectDataSourc e
(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)" <No************ @comcast.netNoS pamMwrote in
message news:O0******** ******@TK2MSFTN GP05.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" <sp*******@love ly.spamwrote in message
news:%2******* *********@TK2MS FTNGP05.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 ObjectDataSourc e on an
ASP.NET web page. When we open the page the Select method (here:
GetCustomer s) 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:DataLi st ID="CustomersLi st" DataSourceID="C ustomerDataSour ce"
runat="server ">
<ItemTemplate >
Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>'
runat="server "/>
</ItemTemplate>
</asp:DataList>
<asp:ObjectDa taSource ID="CustomerDat aSource"
SelectMethod= "GetCustome rs"
TypeName="Cus tomers" runat="server" />

public class Customers
{
public List<CustomerGe tCustomers()
{
Customer test = new Customer();
test.Name = "Uakari Mabuto";
List<Customerli st = 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



Aug 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
4744
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
1
1600
by: misiek | last post by:
Hi all. I have a problem with setting value of some parameter in select command in ObjectDataSource. This is what I did: 1. I created DataSet in designer using some stored procedure, which expects exactly one parameter. Also there was a "Return a data table" method created. 2. I dragged ObjectDataSource to my web page and configured it to use method I created in pont 1.
0
1839
by: David Hubbard | last post by:
I am using a GridView to display a set of objects that have a parent-child relationship. Each object, MyBO, has an ID property that is used to get the children of that object. class MyBO { int _id; String _name;
9
11834
by: J055 | last post by:
Hi I'm trying to get an instance of UserLists to persist after it's been used by the GridView. I understand from the documentation that The OnObjectCreated event allows access to the instance. I have a TotalUsers property which is initiated when the GetUsers method is called, however it is empty after the OnObjectCreated event runs. What am I doing wrong? Is there a way to get the Row count from the GetUsers method (It is a DataTable)?...
1
5019
by: Jan Doggen | last post by:
Hello all, I have a SELECT like this (the 'alert()s are temporary): <FORM method="POST" action="/scripts/runisa.dll?OVB2.132964:PGSPLITVACAFMELDEN:1095144287.9159" id="hulpform" name="hulpform"> <select name="varVervuld" id="varVervuld" onChange="alert('Onchange');Vervuld(this.options);"> <option value="0" selected="selected">&nbsp;</option> <option value=JA>Ja</option>
5
2656
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are simply working with objects in memory. So, it appears as though Microsoft requires that our datamapper classes reside inside a folder called "App_Code", and NO WHERE ELSE. So, has anyone successfully been able to place their datamappers in a...
4
4514
by: chris.c.woodward | last post by:
This event seems to be being raised twice in my codebehind. I have only one SelectMethod and do not have a SelectCountMethod. Its causing a problem because I'm dynamically loading a user control into a PlaceHolder control in the method and am having to do a check to see if it already exists or not otherwise it gets loaded twice. Also it would be nice to figure out what the heck is going on! Here is the code ... protected void...
0
1838
by: TarTar | last post by:
Hello, I have the following code on my ASP.NET page: <asp:DataList ID="CustomersList" DataSourceID="CustomerDataSource" runat="server"> <ItemTemplate> Name: <asp:Label id="lblName" Text='<%# Eval("Name") %>' runat="server"/> </ItemTemplate>
6
3508
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.