473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Why can¡¯t I use an aspx page class as TypeName for ObjectDataSource?

Hello,

I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.Page1¡±
as TypeName of ObjectDataSource, received error message ¡°The type specified
in the TypeName property of ObjectDataSource 'object1' could not be found.¡±,
If I instead use a class in App_Code folder as TypeName, it works find. But
I can¡¯t figure out why it didn¡¯t work for aspx page class?

Here¡¯s the code:

--------- Page1.aspx.cs: ----------

namespace ObjectIssue

{

public partial class Page1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

public List<PersonGetPerson()

{

List<PersonpList = new List<Person>();

pList.Add(new Person("James", 27));

return pList;

}

}

public class Person

{

public Person(string sName, int iAge)

{

_name = sName;

_age = iAge;

}

private string _name;

public string Name

{

get { return _name; }

set { _name = value; }

}

private int _age;

public int Age

{

get { return _age; }

set { _age = value; }

}

}

}

-------------Page1.aspx:----------------------------------------------------------------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs"
Inherits="ObjectIssue.Page1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:ObjectDataSource ID="object1" runat="server"
TypeName="ObjectIssue.Page1" SelectMethod="GetPerson" />

<asp:FormView ID="formView1" runat="server" DataSourceID="object1">

<ItemTemplate>

<%# Eval("Name") %>

</ItemTemplate>

</asp:FormView>

</div>

</form>

</body>

</html>

Nov 8 '08 #1
1 2103
On Nov 8, 5:35*pm, "yanni" <yanni6...@126.comwrote:
Hello,

I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.Page1¡±
as TypeName of ObjectDataSource, received error message ¡°The type specified
in the TypeName property of ObjectDataSource 'object1' could not be found..¡±,
If I instead use a class in App_Code folder as TypeName, it works find. But
I can¡¯t figure out why it didn¡¯t work for aspx page class?

Here¡¯s the code:

--------- Page1.aspx.cs: ----------

namespace ObjectIssue

{

* * public partial class Page1 : System.Web.UI.Page

* * {

* * * * protected void Page_Load(object sender, EventArgs e)

* * * * {

* * * * }

* * * * public List<PersonGetPerson()

* * * * {

* * * * * * List<PersonpList = new List<Person>();

* * * * * * pList.Add(new Person("James", 27));

* * * * * * return pList;

* * * * }

* * }

* * public class Person

* * {

* * * * public Person(string sName, int iAge)

* * * * {

* * * * * * _name = sName;

* * * * * * _age = iAge;

* * * * }

* * * * private string _name;

* * * * public string Name

* * * * {

* * * * * * get { return _name; }

* * * * * * set { _name = value; }

* * * * }

* * * * private int _age;

* * * * public int Age

* * * * {

* * * * * * get { return _age; }

* * * * * * set { _age = value; }

* * * * }

* * }

}

-------------Page1.aspx:--------------------------------------------------- -------------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs"
Inherits="ObjectIssue.Page1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

* * <title>Untitled Page</title>

</head>

<body>

* * <form id="form1" runat="server">

* * <div>

* * * * <asp:ObjectDataSource ID="object1" runat="server"
TypeName="ObjectIssue.Page1" SelectMethod="GetPerson" />

* * * * <asp:FormView ID="formView1" runat="server" DataSourceID="object1">

* * * * * * <ItemTemplate>

* * * * * * * * <%# Eval("Name") %>

* * * * * * </ItemTemplate>

* * * * </asp:FormView>

* * </div>

* * </form>

</body>

</html>
this works to me
Nov 9 '08 #2

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

Similar topics

1
by: Paul | last post by:
Title: What are the Consequences of Aspx page separate from app DLL Hi JL; I am working on a big asp.net application. When we migrate the dll (or dlls) to the production server, all users who are...
1
by: Fabrizio | last post by:
Hi, can and aspx page be resized depending on the requester dysplay resolution? how? Thank you, Fabrizio
5
by: ozie | last post by:
Hi , I am new to ASP.NET. I was reading about Page class in one of the ASP.NET books and am confused with the way the Page class is actually implemented.What is didnt understand in when is this...
9
by: JohnSmith | last post by:
I suspect this is easy, but I have been stumped for a day trying to solve this.. I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code...
1
by: vinod_kanmantha kanmantha via .NET 247 | last post by:
(Type your message here) hi, this is vinod can any one pls tell me how we can convert aspx page into word.This aspx page consists of text boxes when we export this page to word the data in the...
2
by: kermit | last post by:
I have an .net aspx page MyPage.aspx (client side), with code behind MyPage.aspx.vb (server side) I use the pages server On_Load event (.aspx.vb) to create a collection using classes. ...
2
by: kermit | last post by:
I have a .net aspx page MyPage.aspx (client side) with code behind MyPage.aspx.vb (server side). I use the Page_Load event in MyPage.aspx.vb to load data into a multiteir class based...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
6
by: Steve Richter | last post by:
what with the website solution structure not having a namespace, how does the class of one website .aspx page class reference the class of another page in the same website? I have two pages....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.