当前文件路径:DNN/Library/Controls/LabelControl.vb 
1
'
2
' DotNetNuke?- http://www.dotnetnuke.com
3
' Copyright (c) 2002-2008
4
' by DotNetNuke Corporation
5
'
6
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
'
11
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
' of the Software.
13
'
14
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
' DEALINGS IN THE SOFTWARE.
19
'
20
Imports System.IO
21
Imports DotNetNuke.Entities.Modules
22
23
Namespace DotNetNukeNamespace DotNetNuke.UI.UserControls
24
25
/**/''' -----------------------------------------------------------------------------
26
''' <summary>
27
''' LabelControl is a user control that provides all the server code to manage a
28
''' label, including localization, 508 support and help.
29
''' </summary>
30
''' <remarks>
31
''' To implement help, the control uses the ClientAPI interface. In particular
32
''' the javascript function __dnn_Help_OnClick()
33
''' </remarks>
34
''' <history>
35
''' [cnurse] 9/8/2004 Created
36
''' </history>
37
''' -----------------------------------------------------------------------------
38
Public MustInherit Class LabelControlClass LabelControl
39
Inherits System.Web.UI.UserControl
40
41
Controls#Region "Controls"
42
43
Protected WithEvents label As System.Web.UI.HtmlControls.HtmlGenericControl
44
Protected WithEvents cmdHelp As System.Web.UI.WebControls.LinkButton
45
Protected WithEvents imgHelp As System.Web.UI.WebControls.Image
46
Protected WithEvents lblLabel As System.Web.UI.WebControls.Label
47
Protected WithEvents lblHelp As System.Web.UI.WebControls.Label
48
Protected WithEvents pnlHelp As System.Web.UI.WebControls.Panel
49
50
#End Region
51
52
Private Members#Region "Private Members"
53
54
Private _ControlName As String 'Associated Edit Control for this Label
55
Private _HelpKey As String 'Resource Key for the Help Text
56
Private _ResourceKey As String 'Resource Key for the Label Text
57
Private _Suffix As String 'Optional Text that appears after the Localized Label Text
58
Private _cssClass As String 'CssClass applied to label control
59
60
#End Region
61
62
Public Properties#Region "Public Properties"
63
64
/**/''' -----------------------------------------------------------------------------
65
''' <summary>
66
''' ControlName is the Id of the control that is associated with the label
67
''' </summary>
68
''' <value>A string representing the id of the associated control</value>
69
''' <remarks>
70
''' </remarks>
71
''' <history>
72
''' [cnurse] 9/8/2004 Created
73
''' </history>
74
''' -----------------------------------------------------------------------------
75
Public Property ControlName()Property ControlName() As String
76
Get
77
Return _ControlName
78
End Get
79
Set(ByVal Value As String)
80
_ControlName = Value
81
End Set
82
End Property
83
84
/**/''' -----------------------------------------------------------------------------
85
''' <summary>
86
''' HelpKey is the Resource Key for the Help Text
87
''' </summary>
88
''' <value>A string representing the Resource Key for the Help Text</value>
89
''' <remarks>
90
''' </remarks>
91
''' <history>
92
''' [cnurse] 9/8/2004 Created
93
''' </history>
94
''' -----------------------------------------------------------------------------
95
Public Property HelpKey()Property HelpKey() As String
96
Get
97
Return _HelpKey
98
End Get
99
Set(ByVal Value As String)
100
_HelpKey = Value
101
End Set
102
End Property
103
104
/**/''' -----------------------------------------------------------------------------
105
''' <summary>
106
''' HelpText is value of the Help Text if no ResourceKey is provided
107
''' </summary>
108
''' <value>A string representing the Text</value>
109
''' <remarks>
110
''' </remarks>
111
''' <history>
112
''' [cnurse] 9/8/2004 Created
113
''' </history>
114
''' -----------------------------------------------------------------------------
115
Public Property HelpText()Property HelpText() As String
116
Get
117
Return lblHelp.Text
118
End Get
119
Set(ByVal Value As String)
120
lblHelp.Text = Value
121
imgHelp.AlternateText = HtmlUtils.Clean(Value, False)
122
123
'hide the help icon if the help text is ""
124
If Value = "" Then
125
imgHelp.Visible = False
126
End If
127
End Set
128
End Property
129
130
/**/''' -----------------------------------------------------------------------------
131
''' <summary>
132
''' ResourceKey is the Resource Key for the Label Text
133
''' </summary>
134
''' <value>A string representing the Resource Key for the Label Text</value>
135
''' <remarks>
136
''' </remarks>
137
''' <history>
138
''' [cnurse] 9/8/2004 Created
139
''' </history>
140
''' -----------------------------------------------------------------------------
141
Public Property ResourceKey()Property ResourceKey() As String
142
Get
143
Return _ResourceKey
144
End Get
145
Set(ByVal Value As String)
146
_ResourceKey = Value
147
End Set
148
End Property
149
150
/**/''' -----------------------------------------------------------------------------
151
''' <summary>
152
''' Suffix is Optional Text that appears after the Localized Label Text
153
''' </summary>
154
''' <value>A string representing the Optional Text</value>
155
''' <remarks>
156
''' </remarks>
157
''' <history>
158
''' [cnurse] 9/8/2004 Created
159
''' </history>
160
''' -----------------------------------------------------------------------------
161
Public Property Suffix()Property Suffix() As String
162
Get
163
Return _Suffix
164
End Get
165
Set(ByVal Value As String)
166
_Suffix = Value
167
End Set
168
End Property
169
170
/**/''' -----------------------------------------------------------------------------
171
''' <summary>
172
''' Text is value of the Label Text if no ResourceKey is provided
173
''' </summary>
174
''' <value>A string representing the Text</value>
175
''' <remarks>
176
''' </remarks>
177
''' <history>
178
''' [cnurse] 9/8/2004 Created
179
''' </history>
180
''' -----------------------------------------------------------------------------
181
Public Property Text()Property Text() As String
182
Get
183
Return lblLabel.Text
184
End Get
185
Set(ByVal Value As String)
186
lblLabel.Text = Value
187
End Set
188
End Property
189
190
/**/''' -----------------------------------------------------------------------------
191
''' <summary>
192
''' Css style applied to the asp:label control
193
''' </summary>
194
''' <value>A string representing css class name</value>
195
''' <remarks>
196
''' </remarks>
197
''' -----------------------------------------------------------------------------
198
Public Property CssClass()Property CssClass() As String
199
Get
200
Return _cssClass
201
End Get
202
Set(ByVal value As String)
203
_cssClass = value
204
End Set
205
End Property
206
#End Region
207
208
Private Methods#Region "Private Methods"
209
210
/**/''' -----------------------------------------------------------------------------
211
''' <summary>
212
''' GetLocalizedText gets the localized text for the provided key
213
''' </summary>
214
''' <remarks>
215
''' </remarks>
216
''' <param name="key">The resource key</param>
217
''' <param name="ctl">The current control</param>
218
''' <history>
219
''' [cnurse] 9/8/2004 Created
220
''' </history>
221
''' -----------------------------------------------------------------------------
222
Private Function GetLocalizedText()Function GetLocalizedText(ByVal key As String, ByVal ctl As Control) As String
223
'We need to find the parent module
224
Dim parentControl As Control = ctl.Parent
225
Dim localizedText As String
226
227
If TypeOf parentControl Is PortalModuleBase Then
228
'We are at the Module Level so return key
229
'Get Resource File Root from Parents LocalResourceFile Property
230
Dim ctrl As Entities.Modules.PortalModuleBase
231
ctrl = DirectCast(parentControl, PortalModuleBase)
232
localizedText = Services.Localization.Localization.GetString(key, ctrl.LocalResourceFile)
233
Else
234
Dim pi As System.Reflection.PropertyInfo = parentControl.GetType.GetProperty("LocalResourceFile")
235
If Not pi Is Nothing Then
236
'If control has a LocalResourceFile property use this
237
localizedText = Services.Localization.Localization.GetString(key, pi.GetValue(parentControl, Nothing).ToString())
238
Else
239
'Drill up to the next level
240
localizedText = GetLocalizedText(key, parentControl)
241
End If
242
End If
243
244
Return localizedText
245
End Function
246
247
#End Region
248
249
Event Handlers#Region "Event Handlers"
250
251
/**/''' -----------------------------------------------------------------------------
252
''' <summary>
253
''' Page_Load runs when the control is loaded
254
''' </summary>
255
''' <remarks>
256
''' </remarks>
257
''' <history>
258
''' [cnurse] 9/8/2004 Created
259
''' </history>
260
''' -----------------------------------------------------------------------------
261
Private Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
262
Try
263
DotNetNuke.UI.Utilities.DNNClientAPI.EnableMinMax(cmdHelp, pnlHelp, True, Utilities.DNNClientAPI.MinMaxPersistanceType.None)
264
265
'get the localised text
266
If String.IsNullOrEmpty(_ResourceKey) Then
267
'Set Resource Key to the ID of the control
268
_ResourceKey = Me.ID
269
End If
270
271
If (Not String.IsNullOrEmpty(ResourceKey)) Then
272
Dim localText As String = GetLocalizedText(_ResourceKey, Me)
273
If Not String.IsNullOrEmpty(localText) Then
274
Me.Text = localText & _Suffix
275
End If
276
End If
277
278
If String.IsNullOrEmpty(_HelpKey) Then
279
'Set Help Key to the Resource Key plus ".Help"
280
_HelpKey = _ResourceKey & ".Help"
281
End If
282
Dim helpText As String = GetLocalizedText(_HelpKey, Me)
283
If Not String.IsNullOrEmpty(helpText) Then
284
Me.HelpText = helpText
285
End If
286
287
If Not String.IsNullOrEmpty(CssClass) Then
288
lblLabel.CssClass = CssClass
289
End If
290
291
'find the reference control in the parents Controls collection
292
If Not String.IsNullOrEmpty(ControlName) Then
293
Dim c As Control = Me.Parent.FindControl(ControlName)
294
If Not c Is Nothing Then
295
label.Attributes("for") = c.ClientID
296
End If
297
End If
298
299
Catch exc As Exception 'Module failed to load
300
ProcessModuleLoadException(Me, exc)
301
End Try
302
End Sub
303
304
Private Sub imageClick()Sub imageClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdHelp.Click
305
306
pnlHelp.Visible = True
307
308
End Sub
309
310
#End Region
311
312
End Class
313
314
End Namespace
315