Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

including a cs file in an aspx file dont work. Why?

Posted on 2009-05-11
1
Medium Priority
?
398 Views
Last Modified: 2012-05-06
I cant include my cs file in my aspx file.

I get this error.   (the filminfo file is under a folder called App_Code

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0433: The type 'ProjektFilm.Filminfo' exists in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\10920de8\7170bc22\assembly\dl3\eaa4bec6\caa0f9f7_04d2c901\ProjektFilm.DLL' and 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\10920de8\7170bc22\App_Code.2xun89dv.dll'
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ProjektFilm.test" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="ProjektFilm" %>
 
<html>
<head>
<title>ButtonField ButtonType Example</title>
 
<script language="C#" runat="server">
   DataTable Cart;
   DataView CartView;
 
   void Page_Load ( Object src, EventArgs e ) {
      if ( !IsPostBack ) {
 
          myGrid.DataSource = (List<Filminfo>)Session["film"];
          myGrid.DataBind();
      }
 
      if ( Session [ "shoppingSession" ] == null ) {
         Cart = new DataTable ( );
         Cart.Columns.Add ( new DataColumn ( "Item", typeof ( string ) ) );
         Cart.Columns.Add ( new DataColumn ( "Price", typeof ( string ) ) );
         Session [ "shoppingSession" ] = Cart;
      }
      else Cart = ( DataTable ) Session [ "shoppingSession" ];
 
      CartView = new DataView ( Cart );
      shopCart.DataSource = CartView;
      shopCart.DataBind ( );
   }
 
   void updateCart ( Object src, GridViewCommandEventArgs e ) {
      DataRow dr = Cart.NewRow ( );
 
      // get the row index stored in the CommandArgument property
      int index = Convert.ToInt32 ( e.CommandArgument );
 
      // get the GridViewRow where the command is raised
      GridViewRow selectedRow = ( ( GridView ) e.CommandSource ).Rows [ index ];
 
      // for bound fields, values are stored in the Text property of Cells [ fieldIndex ]
      string item = selectedRow.Cells [ 1 ].Text;
      string price = selectedRow.Cells [ 2 ].Text;
 
      if ( e.CommandName == "AddToCart" ) {
         dr [ 0 ] = item; dr [ 1 ] = price;
         Cart.Rows.Add ( dr );
      }
      else {  // remove from Cart
         CartView.RowFilter = "Item='" + item + "'";
         if ( CartView.Count > 0 ) CartView.Delete ( 0 );
         CartView.RowFilter = "";
      }
      shopCart.DataBind ( );
   }
 
   void setButtonStyle ( Object src, GridViewRowEventArgs e ) {
      if ( e.Row.RowType == DataControlRowType.DataRow ) {
         IDataRecord rowView = ( IDataRecord ) e.Row.DataItem;
         TableCellCollection cells = e.Row.Cells;
         ( ( Button ) cells [ 3 ].Controls [ 0 ] ).CssClass = "add";
         ( ( Button ) cells [ 4 ].Controls [ 0 ] ).CssClass = "remove";
      }
   }
</script>
</head>
 
<body>
 
<div class="header"><h3>&nbsp;</h3>
    <h3>Lägg till film</h3></div>
 
<p class="small">&nbsp;<hr size=1 width=90%>
 
<form id="Form1" runat="server">
 
<table cellpadding="5">
<tr valign="top">
   <td><b>Product List</b>
 
      <asp:gridview id="myGrid" runat="server"
         cellpadding=5 font-size="8pt"
         gridlines="horizontal"
         autogeneratecolumns=false
         onRowCreated="setButtonStyle"
         onRowCommand="updateCart">
 
         <headerstyle backcolor="darkslategray"
            forecolor="khaki" font-bold />
 
         <rowstyle backcolor="ivory" verticalalign="top" />
 
         <columns>
 
            <asp:boundfield
               headertext="Title"
               datafield="title" />
 
            <asp:boundfield
               headertext="Item"
               datafield="title_id" />
 
            <asp:boundfield
               headertext="Price"
               datafield="price"
               dataformatstring="{0:c}"
               itemstyle-horizontalalign="right" />
 
            <asp:buttonfield
               text=" + "
               buttontype="button"
               commandname="AddToCart"  />
 
            <asp:buttonfield
               text=" - "
               buttontype="button"
               commandname="RemoveFromCart" />
 
         </columns>
 
      </asp:gridview>
   </td>
 
   <td><b>Shopping Cart</b>
 
      <asp:gridview id="shopCart" runat="server"
         cellpadding=5 font-size="8pt"
         headerstyle-backcolor="darkslategray"
         headerstyle-forecolor="khaki"
         headerstyle-font-bold
         rowstyle-backcolor="ivory"
         rowstyle-verticalalign="top" />
 
   </td></tr>
</table>
 
</form>
 
<hr size=1 width=90%>
 
</body>
</html>

Open in new window

0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
tillgeffken earned 2000 total points
ID: 24352178
Taken from ScottGu's Blog:

"VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes     it finds under the /App_Code directory of an application at runtime, you explictly *DO NOT* want to      store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder.     If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project     assembly, and then again at runtime by ASP.NET.  The result will most likely be a "could not load type"     runtime exception -- caused because you have duplicate type names in your application.  Instead, you      should store your class files in any other directory of your project other than one named "app_code"."
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question