Salut à tous
j'ai créé une biblitheque de classes (dll) dans laquelle j'ai créé un webcontrol;
Celui ci a pour but de servir de DebugConsole dans des applications AJAX, donc je voudrais pouvoir lui donner des infos à ajouter au fur et à mesure du chargement de la page ASP.NET...
voici le code complet du webcontrol :
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Web.UI.HtmlControls; namespace TSV_WebUtilities { [DefaultProperty("Text")] [ToolboxData("<{0}:WebDebugConsole runat=server></{0}:WebDebugConsole>")] public class WebDebugConsole : WebControl { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] string TextToDisplay; public string Content { get { String s = (String)ViewState["DebugInfoContent"]; return ((s == null) ? String.Empty : s); } set { ViewState["DebugInfoContent"] = value; } } public WebDebugConsole() { } static string DefaultBGcolor = "#ECECEC"; string beginTable = "<table " + "border=1 " + "align='center' " + "style=\"background='" + DefaultBGcolor + "';\" " + "width='50%'" + "><tr><td><table width='100%' cellspacing='0' >"; string rowStart = "<tr " + "onmouseover=\"this.style.background='white';\" " + "onmouseout=\"this.style.background='" + DefaultBGcolor + "';\" " + "background=\"" + DefaultBGcolor + "\" " + "class=\"normal\">" + "<td style='margin:5px 5px 5px 5px '>"; //string rowStart = "<tr><td>"; string cellSeparator = "</td><td>"; string rowEnd = "</td></tr>"; string endTable = "</table></td></tr></table>"; public void Write_Info(string info) { ViewState["DebugInfoType"] = "INFORMATION"; ViewState["DebugInfoContent"] = info; ViewState["DebugInfoColor"] = "green"; //WriteLog("INFORMATION", "" + info, "green"); } public void Write_Warning(string info) { ViewState["DebugInfoType"] = "WARNING"; ViewState["DebugInfoContent"] = info; ViewState["DebugInfoColor"] = "orange"; //WriteLog("WARNING", info, "orange"); } public void Write_Error(string info) { ViewState["DebugInfoType"] = "ERROR"; ViewState["DebugInfoContent"] = info; ViewState["DebugInfoColor"] = "red"; //WriteLog("ERROR", info, "red"); } protected override void OnInit(EventArgs e) { base.OnInit(e); } protected override void OnLoad(EventArgs e) { //base.OnLoad(e); if (!Page.IsPostBack) { TextToDisplay = ""; if (ViewState["DebugInfoType"] == null) ViewState["DebugInfoType"] = ""; if (ViewState["DebugInfoContent"] == null) ViewState["DebugInfoContent"] = ""; if (ViewState["DebugInfoColor"] == null) ViewState["DebugInfoColor"] = ""; } } protected override void RenderContents(HtmlTextWriter output) { string InfoType = ViewState["DebugInfoType"].ToString(); string info = ViewState["DebugInfoContent"].ToString(); string color = ViewState["DebugInfoColor"].ToString(); if (ViewState["ContentToStore"] == null) ViewState["ContentToStore"] = ""; TextToDisplay = ViewState["ContentToStore"].ToString() + rowStart + "<font color=" + color + ">" + "*" + "</font>" + cellSeparator + "<font color=" + color + ">" + InfoType + cellSeparator + "<font color=" + color + ">" + DateTime.Now.ToLongTimeString() + "</font>" + cellSeparator + "<font color=" + color + ">" + info + "</font>" + rowEnd; #region output UserControl string FullContent = beginTable + TextToDisplay + endTable; ViewState["ContentToStore"] = TextToDisplay; output.Write(FullContent); #endregion } } }
Mon problème principal est que j'arrive à insérer ma console debug dans ma page, mais par contre impossible de faire persister son viewstate !!
Voici donc plusieurs question que je n'arrive pas à résoudre :
-> Comment faire - si c'est possible - pour dire au contrôle de s'intégrer automatiquement en haut de la page dès qu'il est instancié, au lieu de le créer en dur dans la page ?
-> comment lui faire persister le viewstate pour ne pas qu'il écrase les anciennes données à chaque postback ?
pouvez-vous m'aider ?
Bye
Nico
Partager