Bonjour,

j'aimerai utiliser une classe dans une page aspx. mais je ne sais pas comment on fait.

je vous un donne exemple ca sera plus simple :

page default2.aspx :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Je suis <%= Nom %> <%= Prenom %><br/>
	et j'ai <%= Age %> 
    </div>
    </form>
</body>
</html>
---------------------

page Default2.aspx.cs :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Monsite;
 
public partial class Default2 : System.Web.UI.Page
{
	protected string Nom ;
	protected string Premon ;
	protected int	 Age ;
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
		Nom = "Toto" ; 
 
		Personne p = new Personne();
 
		p.initialise("Dupont","Charles", 45 );
 
		Nom 	= m.Nom ;
		Premon 	= m.Premon;
		Age 	= m.Age ;
 
    }
}
-------------------------------

classe Personne :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace Monsite {
 
	public class Personne {
 
 
		// attributs
		private string prenom;
		private string nom;
		private int age ;
 
		// méthode
		public void initialise(string P, string N, int age){
		this.prenom	= P;	
		this.nom	= N;
		this.age 	= age;
		}
 
		public 	int Age {
			get { return this.age;}
			set { this.age = value;}
		}
 
		public 	string Nom {
			get { return this.nom;}
			set { this.nom = value;}
		}
 
		public 	string Prenom {
			get { return this.prenom;}
			set { this.prenom = value;}
		}
	}
}
j'ai compilé la classe Personne et mis la dll ds le dossier "bin".
--------------------------------

et j'ai une erreur de compilation :

Compilation Error
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: CS0246: The type or namespace name 'Monsite' could not be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 5: using System.Web.UI.WebControls;
Line 6:
Line 7: using Monsite;
Line 8:
Line 9: public partial class Default2 : System.Web.UI.Page
cela fait des jours que je cherche mais je ne trouve pas

Merci