p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Problem With Inheritance (http://p2p.wrox.com/showthread.php?t=41631)

jazzcatone April 23rd, 2006 10:41 AM

Problem With Inheritance
 
  Hello and thank you for taking a moment to read this message.The practice of inheritance is something as a developer I am still struggling with a little bit. I have a page called productcatalog.aspx. It contains the following line of code.

<%@ Page language="c#" Codebehind="productcatalog.aspx.cs" AutoEventWireup="false" Inherits="ShoppingCartCookies.WebForm1" %>
Everytime I go to compile VS 2005 throws me the following build error:

Error 2 Could not load type'ShoppingCartCookies.WebForm1'. C:\Documents and Settings\Jason Livengood\My Documents\Visual Studio 2005\WebSites\WebSite8\productcatalog.aspx 1

I was wondering if anybody could tell me where my mistake is. I would appreciate any help anybody can give. Below is my codebehind for the page.

Thank You,

Jason


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace ShoppingCartCookies
{
    public class WebForm1 : System.Web.UI.Page

    {
        protected System.Web.UI.WebControls.Button Button1;
        protected System.Web.UI.WebControls.DataGrid DataGrid1;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGrid();
            }
        }


        private void BindGrid()
        {
            SqlDataAdapter da = new SqlDataAdapter("select * from products", @"data source=.\vsdotnet;initial catalog=northwind;user id=sa");
            DataSet ds = new DataSet();
            da.Fill(ds, "products");

            DataGrid1.DataSource = ds;
            DataGrid1.DataBind();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexCh anged);
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            ArrayList arr;
            if (Session["mycart"] != null)
            {
                arr = (ArrayList)Session["mycart"];
            }
            else
            {
                arr = new ArrayList();
                Session["mycart"] = arr;
            }

            CShoppingCartItem item = new CShoppingCartItem();
            item.ProductID = int.Parse(DataGrid1.SelectedItem.Cells[1].Text);
            item.ProductName = DataGrid1.SelectedItem.Cells[2].Text;
            item.UnitPrice = decimal.Parse(DataGrid1.SelectedItem.Cells[3].Text);
            item.Quantity = 1;
            arr.Add(item);
        }

        private void Button1_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("cart.aspx");
        }
    }
}




Imar April 23rd, 2006 11:33 AM

Hi there,

This is code from a ASP.NET 1.x page, which will not run as is on 2005

For example, you need to change the page directive attribute of Codebehind to CodeFile. There may be more errors though. The easiest things is to create a new page in VS 2005, and then manually copy the relevant parts from the old page to the new page. Alternatively, you can use the upgrade wizard to upgrade your old site to VS 2005 / .NET 2 format.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004


All times are GMT -4. The time now is 09:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.