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/ [...] 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 :
- <%@ Page Language="C#" Inherits="a" Src="a.cs" %>
- <%@ Reference Control="ab.ascx" %>
- <html>
- <head>
- </head>
- <form runat="server">
- <body style="FONT: 10pt verdana">
- <p>
- </p>
- <p>
- ccccc
- </p>
- <p>
- eggg
- </p>
- <p>
- <asp:Button id="BtnAcheter" onclick="BtnAcheter_Click" Text="Acheter" runat="server"></asp:Button>
- </p></form>
- </body>
- </html>
|
a.cs
Code :
- using System;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Web.UI;
- using System.Web;
- //ref control=ab.ascx;
-
-
- public class a : System.Web.UI.Page {
-
-
-
- void Page_Load(Object sender, EventArgs E) {
-
-
- }
-
- protected void BtnAcheter_Click(object sender, EventArgs e) {
- Control c1 = LoadControl("ab.ascx");
- ((ab)c1).ecrire();
- }
- }
|
ab.ascx
Code :
- <%@ Control ClassName="abc" Language="C#" Inherits="ab" Src="ab.cs" %>
- <p>
- <asp:Label id="Label1" runat="server">Label</asp:Label>
- </p>
|
ab.cs
Code :
- using System;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Web.UI;
- using System.Web;
-
-
-
- public class ab : System.Web.UI.UserControl{
-
- Label Label1;
-
- public void ecrire() {
- Label1.Text="ok";
- }
- }
|
merci pour votre aide
