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

Discussion in 'ASP .Net' started by yanni, Nov 8, 2008.

  1. yanni

    yanni Guest

    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<Person> GetPerson()

    {

    List<Person> pList = 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>
     
    yanni, Nov 8, 2008
    #1
    1. Advertising

  2. On Nov 8, 5:35 pm, "yanni" <> wrote:
    > 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<Person> GetPerson()
    >
    >         {
    >
    >             List<Person> pList = 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
     
    Alexey Smirnov, Nov 9, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Lilja
    Replies:
    3
    Views:
    866
    Eric Lilja
    Apr 23, 2005
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,230
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    1
    Views:
    782
  4. Replies:
    6
    Views:
    647
    Victor Bazarov
    Oct 20, 2005
  5. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    375
    Rolf Magnus
    Mar 14, 2006
Loading...

Share This Page