Procédure pour importer un ascx depuis le code behind

tomtom41 Messages postés 8 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 26 avril 2006 - 24 mai 2005 à 17:54
tomtom41 Messages postés 8 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 26 avril 2006 - 24 mai 2005 à 21:14
voila ca fait 3h que je suis dessus et je n'y arrive pas
quelle est la procédure pour importer un ascx afin de puis utiliser le type du .ascx ?

j'ai bien compris comment faire mais le problème c'est ca :

MonControl MC = (MonControl) LoadControl("MonControl.ascx");

car il me dit qu'il n'arrive pas à trouver MonControl...je ne peux donc pas faire de cast et donc pas faire mes méthodes voulues

j'ai trouvé ca [http://msdn.microsoft.com/library/fre/default.asp?url=/library/FRE/cpguide/html/cpcondevelopingusercontrolsincode-behindfile.asp http://msdn.microsoft.com/library/ [...] ndfile.asp] mais sans effet

bon alors voila j'ai fait un test.
quand je clique sur le bouton cela doit afficher ok.

a.aspx avec a.cs
ab.ascx avec ab.cs

voici mon erreur lors de l'execution de a.aspx :



Citation :

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 'ab' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 18: protected void BtnAcheter_Click(object sender, EventArgs e) {
Line 19: Control c1 = LoadControl("ab.ascx");
Line 20: ((ab)c1).ecrire();
Line 21: }
Line 22: }

Source File: C:\projets\site_portail\pages\a.cs Line: 20


Mes fichiers :

a.aspx :

Code :

<LI><%@ Page Language="C#" Inherits="a" Src="a.cs" %>
<LI><%@ Reference Control="ab.ascx" %>
<LI><html>
<LI><head>
<LI></head>
<LI><form runat="server">
<LI>
<LI>
<LI>

<LI>
<LI> ccccc
<LI>

<LI>
<LI> eggg
<LI>

<LI>
<LI> &nbsp;
<LI>

</form>
<LI>
<LI></html></LI>


a.cs

Code :

<LI>using System;
<LI>using System.Web.UI.WebControls;
<LI>using System.Data;
<LI>using System.Web.UI;
<LI>using System.Web;
<LI>//ref control=ab.ascx;
<LI>
<LI>
<LI> public class a : System.Web.UI.Page {
<LI>
<LI>
<LI>
<LI> void Page_Load(Object sender, EventArgs E) {
<LI>
<LI>
<LI> }
<LI>
<LI> protected void BtnAcheter_Click(object sender, EventArgs e) {
<LI> Control c1 = LoadControl("ab.ascx");
<LI> ((ab)c1).ecrire();
<LI> }
<LI>}</LI>


ab.ascx

Code :

<LI><%@ Control ClassName="abc" Language="C#" Inherits="ab" Src="ab.cs" %>
<LI>
<LI> Label
<LI>

</LI>


ab.cs

Code :

<LI>using System;
<LI>using System.Web.UI.WebControls;
<LI>using System.Data;
<LI>using System.Web.UI;
<LI>using System.Web;
<LI>
<LI>
<LI>
<LI> public class ab : System.Web.UI.UserControl{
<LI>
<LI> Label Label1;
<LI>
<LI> public void ecrire() {
<LI> Label1.Text="ok";
<LI> }
<LI>}</LI>


merci pour votre aide

2 réponses

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
24 mai 2005 à 18:01
l'erreur viendrait pas de la :

<%@ Control ClassName="abc" Language="C#" Inherits="ab" Src="ab.cs" %>



pourquoi le abc ?



Sinon si tu met un point d'arret ca te donne quoi comme type ?



ou alors si tu fais response.write(c1.getType.toString()); ca te dit
quoi comme type ? (faut bien sur enlever la ligne qui plante)

<hr>Cyril - MCP ASP.net
Webmaster de : Hoshimi.CodeS-SourceS.fr<
0
tomtom41 Messages postés 8 Date d'inscription mardi 24 mai 2005 Statut Membre Dernière intervention 26 avril 2006
24 mai 2005 à 21:14
j'ai mis abc car il refusait "ab".
si je vire le cast ca marche donc c'est bien le type qui merde
0
Rejoignez-nous