473,771 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hello,

I'm creating asp.net 2.0 web site app, I tried to use ¡°ObjectIssue.P age1¡±
as TypeName of ObjectDataSourc e, received error message ¡°The type specified
in the TypeName property of ObjectDataSourc e '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.P age

{

protected void Page_Load(objec t sender, EventArgs e)

{

}

public List<PersonGetP erson()

{

List<PersonpLis t = 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="Objec tIssue.Page1" %>

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

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

<head runat="server">

<title>Untitl ed Page</title>

</head>

<body>

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

<div>

<asp:ObjectData Source ID="object1" runat="server"
TypeName="Objec tIssue.Page1" SelectMethod="G etPerson" />

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

<ItemTemplate >

<%# Eval("Name") %>

</ItemTemplate>

</asp:FormView>

</div>

</form>

</body>

</html>

Nov 8 '08 #1
1 2126
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.P age1¡±
as TypeName of ObjectDataSourc e, received error message ¡°The type specified
in the TypeName property of ObjectDataSourc e '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.P age

* * {

* * * * protected void Page_Load(objec t sender, EventArgs e)

* * * * {

* * * * }

* * * * public List<PersonGetP erson()

* * * * {

* * * * * * List<PersonpLis t = 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="Objec tIssue.Page1" %>

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

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

<head runat="server">

* * <title>Untitl ed Page</title>

</head>

<body>

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

* * <div>

* * * * <asp:ObjectData Source ID="object1" runat="server"
TypeName="Objec tIssue.Page1" SelectMethod="G etPerson" />

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

* * * * * * <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
2212
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 login into the application are pumped off. In fact we must close down the server (to preserve users from being logged on and thinking they are updating data when it is in fact lost when we move the dlls to the the applications bin directory)....
1
2528
by: Fabrizio | last post by:
Hi, can and aspx page be resized depending on the requester dysplay resolution? how? Thank you, Fabrizio
5
1833
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 Page class created ? Is it when the ASPX file is requested for the first time ? Is this executable Page object saved somewhere in the server hard disk space or is it available only in the memory ? I would really like to know more about how all...
9
2975
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 in that class file to be able to read and write the controls on the aspx pages. For example, on all the aspx pages, I'll have a label named label1. From code in the class file, I want to be able to do something like label1.text = "hello world I...
1
3618
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 table cell is rearranged. so pls help me in sorting out this problem. -------------------------------- From: vinod_kanmantha kanmantha ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/)
2
1308
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. Public Class CollectionPage Inherits Web.UI.Page
2
1635
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 collection. MyCollection(sYear).cMonths(sMonth).cDays(sDay).cEvents(sID).EventText My problem arrives when I try to access this collection from the page (MyPage.aspx).
1
6870
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 and page loading/rendering lifecycle.... Ok, now for the question: I have an ASPX page (page.aspx), and I have a UserControl (control.ascx). The UserControl has one textbox on the control, and one button control. I have added a public property...
6
12505
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. _Default.aspx and Default2.aspx. How would I call a static or instance method in Default2 from _Default ? assuming the answer is to qualify with the namespace, the question is what is the namespace of the two pages?
0
9619
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
9454
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
10260
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
10102
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
10038
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
8933
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
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.