Bonjour,
je developpe actuellement un composant sous forme de DLL en asp.net c# et à un certain moment je dois ajouter des contrôles dans le dit composant.
J'ai donc procéder comme suit :
Attributs de classe :
private DropDownList DropDownList2 = null;
Code :
1 2 3 4
| DropDownList2 = new DropDownList();
DropDownList2.ID = "DropDownList2";
Controls.Add(DropDownList2);
DropDownList2.Attributes.Add("onchange", "ajax();"); |
Jusque là pas de problème ma dropDownList s'insere parfaitement dans mon composant.
Malheureusement un peu plus loin dans mon handler de callback AJAX je fais :
1 2 3 4 5
| System.IO.TextWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(stringWriter);
DropDownList2.RenderControl(htw);
htw.Flush();
retourCallBack = stringWriter.ToString(); |
Mais la malheur, au moment d'executer la ligne :
DropDownList2.RenderControl(htw);
il me dit :
Control 'TaskManager1_ZoomEntite_Task_DLL1_DropDownList2' of type 'DropDownList' must be placed inside a form tag with runat=server.
Comment faire au moment de la création de mon contrôle pour prendre en compte un runat=server.
(jai déjà eu l'idée stupide de faire
DropDownList2.Attributes.Add("runat", "server"); et effectivement c'est stupide).
Merci à vous
AH
Partager