Het wilt niet echt lukken om het probleem op te lossen, dus zal even de code die ik nu gebruik van de control hieronder laten zien:
Naampie: mxMenuBar.cs
C#:
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
| using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace MenuBarControl
{
public class MenuBarItem: System.Web.UI.Control
{
private String name;
private String imageUrl;
private string url;
private String text;
public MenuBarItem():this ("", "", "", ""){}
public MenuBarItem (String name, String text, string url, String imageUrl)
{
this.name = name;
this.text = text;
this.url = url;
this.imageUrl = imageUrl;
}
public String Name
{
get
{
return name;
}
set
{
name = value;
}
}
public String Text
{
get
{
return text;
}
set
{
text = value;
}
}
public String Url
{
get
{
return url;
}
set
{
url = value;
}
}
public String ImageUrl
{
get
{
return imageUrl;
}
set
{
imageUrl = value;
}
}
}
[ParseChildren(true, "MenuBarItems")]
public class MenuBar : System.Web.UI.Control
{
protected ArrayList menuBarItems = new ArrayList();
protected System.Web.UI.WebControls.Table tblMenu;
protected string imagePath;
protected string target;
protected string defaultClass;
protected string hoverClass;
protected string hoverOutClass;
protected string hoverDownClass;
public string ImagePath
{
get
{
return this.imagePath;
}
set
{
this.imagePath = value;
}
}
public string Target
{
get
{
return this.target;
}
set
{
this.target = value;
}
}
public string DefaultClass
{
get
{
return this.defaultClass;
}
set
{
this.defaultClass = value;
}
}
public string HoverClass
{
get
{
return this.hoverClass;
}
set
{
this.hoverClass = value;
}
}
public string HoverOutClass
{
get
{
return this.hoverOutClass;
}
set
{
this.hoverOutClass = value;
}
}
public string HoverDownClass
{
get
{
return this.hoverDownClass;
}
set
{
this.hoverDownClass = value;
}
}
public ArrayList MenuBarItems
{
get
{
return menuBarItems;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
Table tblMenu = new Table();
tblMenu.HorizontalAlign = HorizontalAlign.Center;
tblMenu.CellPadding = 5;
tblMenu.CellSpacing = 5;
tblMenu.CssClass = this.defaultClass;
tblMenu.Width = Unit.Parse("100%");
foreach (MenuBarItem menuBarItem in MenuBarItems)
{
TableRow tblRowItem = new TableRow();
tblRowItem.ID = "row_" + menuBarItem.Name;
tblRowItem.Attributes["onClick"] = (this.target != null ? target + ".location='" + menuBarItem.Url + "?" + Page.Request.QueryString + "'" : "top.parent.location='" + menuBarItem.Url + "?" + Page.Request.QueryString + "'");
tblRowItem.Attributes["onMouseOver"] = "this.className='" + this.hoverClass + "'";
tblRowItem.Attributes["onMouseOut"] = "this.className='" + this.hoverOutClass + "'";
tblRowItem.Attributes["onMouseDown"] = "this.className='" + this.hoverDownClass + "'";;
tblRowItem.Attributes["onMouseUp"] = "this.className='" + this.hoverClass + "'";;
TableCell tblColItem = new TableCell();
tblColItem.HorizontalAlign = HorizontalAlign.Center;
tblColItem.BorderWidth = 1;
tblColItem.BorderStyle = BorderStyle.NotSet;
ImageButton imgBtnItem = new ImageButton();
imgBtnItem.ID = "img_" + menuBarItem.Name;
imgBtnItem.ImageUrl = this.imagePath + "/" + menuBarItem.ImageUrl;
Label lblItem = new Label();
lblItem.Text = menuBarItem.Text;
tblColItem.Controls.Add(imgBtnItem);
tblColItem.Controls.Add(new LiteralControl("<br>"));
tblColItem.Controls.Add(lblItem);
tblRowItem.Cells.Add(tblColItem);
tblMenu.Rows.Add(tblRowItem);
}
Controls.Add(tblMenu);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
} |
Dit is .ASPX file:
C#:
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
| <%@ Page Language="C#" %>
<%@ Register TagPrefix="Maraex" Namespace="MenuBarControl" Assembly="Maraex.MenuBar" %>
<HTML>
<HEAD>
<TITLE>Menubar test</TITLE>
</HEAD>
<style type="text/css">
.hover {
cursor: hand;
filter: none;
border-left : 1px solid buttonhighlight;
border-right : 1px solid black;
border-top : 1px solid buttonhighlight;
border-bottom : 1px solid black;
}
.hoverOut {
cursor: hand;
filter: none;
border-left : 1px solid gray;
border-right : 1px solid gray;
border-top : 1px solid gray;
border-bottom : 1px solid gray;
}
.hoverDown {
cursor: hand;
filter: none;
border-left : 1px solid black;
border-right : 1px solid buttonhighlight;
border-top : 1px solid black;
border-bottom : 1px solid buttonhighlight;
}
.default {
cursor: hand;
color: white;
font-family: verdana;
font-size: 10px;
border-color: gray;
}
</style>
<body marginheight="0" style="overflow:hidden;" bgcolor="gray">
<form id="pageForm" runat="server">
<Maraex:MenuBar runat="server"
ID="MenuBar"
Target="top.contentPageFrame"
ImagePath="/images/page"
DefaultClass="default"
HoverClass="hover"
HoverOutClass="hoverOut"
HoverDownClass="hoverDown"
>
<Maraex:MenuBarItem
Name="Page"
ImageUrl="properties.gif"
Url="modifyPage.aspx?id=<%=pageId%>"
Text="Pagina"
/>
<Maraex:MenuBarItem
Name="Editor"
ImageUrl="editor.gif"
Url="modifyPageEditor.aspx?id=<%=pageId%>"
Text="Editor" />
<Maraex:MenuBarItem
Name="Components"
ImageUrl="components.gif"
Url="modifyPageComponents.aspx?id=<%=pageId%>"
Text="Components"
/>
<Maraex:MenuBarItem
Name="Preview"
ImageUrl="preview.gif"
Url="previewPage.aspx?id=<%=pageId%>"
Text="Preview"
/>
</Maraex:MenuBar>
</form>
</body>
</html> |
Nu zou ik die `Request.QueryString["id"]` willen laten parsen, maar het is mij een beetje onduidelijk op welke manier.
Nu dacht ik ook om bijv. in de codebehind van die .aspx file het volgende te doen:
Naampie: menubar.aspx.cs
C#:
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
| using System;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using MenuBarControl;
namespace Cms {
public class displayMenuPage : System.Web.UI.Page
{
protected MenuBarControl.MenuBar MenuBar;
public string pageId;
/**
* Page Initialize
*
* @param object Sender
* @param event Arguments
*
* @return Control The parsed document
*/
void Page_Init(Object sender, EventArgs e) {
pageId = Request.QueryString["Id"];
}
/**
* Page load
*
* @param object Sender
* @param event Arguments
*
* @return Control The parsed document
*/
public void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
MenuBarItem myItem = new MenuBarItem();
myItem.Name = "test";
myItem.ImageUrl = "properties.gif";
myItem.Url = "tes.aspx";
myItem.Text = "test";
phMenuBar.Controls.Add(myItem);
}
}
}
} |
Maar ik krijg niet de naam "test" als item erbij te zien, hij geeft geen foutmelding ofsow maar hij laat gewoon niet die "test" erbij zien.
Wie weet wat het probleem is en kan mij door deze code helpen wat het probleem precies is en wat ik moet doen om het op te lossen.
Alvast bedankt voor de reacties.