-
Notifications
You must be signed in to change notification settings - Fork 11
/
ContactForm.ascx.vb
executable file
·691 lines (555 loc) · 37.4 KB
/
ContactForm.ascx.vb
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports System.IO
Namespace Ventrian.PropertyAgent
Partial Public Class ContactForm
Inherits PropertyAgentControl
#Region " Private Members "
Dim _contactFormFields As List(Of ContactFieldInfo)
Dim _email As String = ""
#End Region
#Region " Private Properties "
Public ReadOnly Property ContactFormFields() As List(Of ContactFieldInfo)
Get
If (_contactFormFields Is Nothing) Then
Dim objContactFieldController As New ContactFieldController()
_contactFormFields = objContactFieldController.List(Me.ModuleID)
If (_contactFormFields.Count = 0) Then
_contactFormFields = New List(Of ContactFieldInfo)
For Each contactFormField As ContactDefaultFieldType In System.Enum.GetValues(GetType(ContactDefaultFieldType))
Select Case contactFormField
Case ContactDefaultFieldType.Name
Dim objCustomField As New ContactFieldInfo
objCustomField.ContactFieldID = ContactDefaultFieldType.Name
objCustomField.Name = "Name"
objCustomField.Caption = "Name"
objCustomField.CaptionHelp = "Name.Help"
objCustomField.FieldType = CustomFieldType.OneLineTextBox
objCustomField.DefaultValue = String.Empty
objCustomField.IsRequired = Me.PropertySettings.ContactRequireName
If (Me.PropertySettings.ContactHideName = False) Then
_contactFormFields.Add(objCustomField)
End If
Case ContactDefaultFieldType.Phone
Dim objCustomField As New ContactFieldInfo
objCustomField.ContactFieldID = ContactDefaultFieldType.Phone
objCustomField.Name = "Phone"
objCustomField.Caption = "Phone"
objCustomField.CaptionHelp = "Phone.Help"
objCustomField.FieldType = CustomFieldType.OneLineTextBox
objCustomField.DefaultValue = String.Empty
objCustomField.IsRequired = Me.PropertySettings.ContactRequirePhone
If (Me.PropertySettings.ContactHidePhone = False) Then
_contactFormFields.Add(objCustomField)
End If
Case ContactDefaultFieldType.Email
Dim objCustomField As New ContactFieldInfo
objCustomField.ContactFieldID = ContactDefaultFieldType.Email
objCustomField.Name = "Email"
objCustomField.Caption = "Email"
objCustomField.CaptionHelp = "Email.Help"
objCustomField.FieldType = CustomFieldType.OneLineTextBox
objCustomField.DefaultValue = String.Empty
objCustomField.IsRequired = Me.PropertySettings.ContactRequireEmail
If (Me.PropertySettings.ContactHideEmail = False) Then
_contactFormFields.Add(objCustomField)
End If
Case ContactDefaultFieldType.Message
Dim objCustomField As New ContactFieldInfo
objCustomField.ContactFieldID = ContactDefaultFieldType.Message
objCustomField.Name = "Message"
objCustomField.Caption = "Message"
objCustomField.CaptionHelp = "Message.Help"
objCustomField.FieldType = CustomFieldType.MultiLineTextBox ' .RichTextBox
objCustomField.DefaultValue = String.Empty
objCustomField.IsRequired = True
_contactFormFields.Add(objCustomField)
End Select
Next
End If
End If
Return _contactFormFields
End Get
End Property
Private ReadOnly Property MailTo() As String
Get
If (_email <> "") Then
Return _email
End If
Select Case Me.PropertySettings.ContactDestination
Case DestinationType.PropertyOwner
If (CurrentProperty Is Nothing) Then
Return Null.NullString
Else
If CurrentProperty.AuthorID <> Null.NullInteger Then
If CurrentProperty.Email.Trim() <> "" Then
Return CurrentProperty.Email.Trim()
Else
Return PropertySettings.ContactBCC.Trim()
End If
Else
Return PropertySettings.ContactBCC.Trim()
End If
End If
Case DestinationType.PortalAdmin
Return PortalSettings.Email
Case DestinationType.CustomEmail
Return PropertySettings.ContactCustomEmail
Case DestinationType.CustomField
If (PropertySettings.ContactDestination = DestinationType.CustomField) Then
If (PropertySettings.ContactField <> Null.NullInteger) Then
For Each objCustomField As CustomFieldInfo In CustomFields
If (objCustomField.CustomFieldID = PropertySettings.ContactField) Then
If (CurrentProperty.PropertyList.Contains(objCustomField.CustomFieldID)) Then
Return CurrentProperty.PropertyList(objCustomField.CustomFieldID).ToString()
Else
Return PortalSettings.Email
End If
End If
Next
Else
Return PortalSettings.Email
End If
Else
Return PortalSettings.Email
End If
End Select
Return ""
End Get
End Property
Private ReadOnly Property ResourceFile() As String
Get
Return "~/DesktopModules/PropertyAgent/App_LocalResources/ContactForm"
End Get
End Property
#End Region
#Region " Public Properties "
Public Property EmailAddress() As String
Get
Return _email
End Get
Set(ByVal value As String)
_email = value
End Set
End Property
#End Region
#Region " Private Methods "
Private Sub BindDetails()
rptDetails.DataSource = ContactFormFields
rptDetails.DataBind()
If PropertySettings.ContactWidth.Contains("%") Then
tblContactForm.Width = Unit.Percentage(PropertySettings.ContactWidth.Trim("%"))
Else
tblContactForm.Width = Unit.Pixel(PropertySettings.ContactWidth.Trim("px"))
End If
cmdSubmit.Text = Localization.GetString("cmdSubmit", ResourceFile)
End Sub
Private Function RenderControlAsString(ByVal objControl As Control) As String
Dim sb As New StringBuilder
Dim tw As New StringWriter(sb)
Dim hw As New HtmlTextWriter(tw)
objControl.RenderControl(hw)
Return sb.ToString()
End Function
#End Region
#Region " Event Handlers "
Private Sub Page_Initialization(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Try
BindDetails()
trCaptcha.Visible = PropertySettings.ContactUseCaptcha
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If Not IsPostBack Then
If CurrentProperty Is Nothing OrElse (CurrentProperty.Email.Trim() = "" And PropertySettings.ContactDestination = DestinationType.PropertyOwner) Then
phContactForm.Visible = False
Else
phContactForm.Visible = True
cmdSubmit.ValidationGroup = ModuleKey
cmdSubmit.CssClass = PropertySettings.ButtonClass
End If
End If
trCaptcha.Visible = PropertySettings.ContactUseCaptcha
'ctlCaptcha.ErrorMessage = Localization.GetString("ctlCaptcha.ErrorMessage", Me.ResourceFile)
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Dim hostSettings As Dictionary(Of String, String) = DotNetNuke.Entities.Controllers.HostController.Instance.GetSettingsDictionary()
Try
lblSubmitResults.Text = String.Empty
If Not (mlFlexCaptcha.mlValidate()) Then
lblSubmitResults.Text = Localization.GetString("ctlCaptcha.ErrorMessage", Me.ResourceFile)
lblSubmitResults.CssClass = "NormalRed"
End If
If Page.IsValid AndAlso (PropertySettings.ContactUseCaptcha = False OrElse mlFlexCaptcha.mlValidate()) Then
Dim objLayoutController As New LayoutController(PortalSettings, PropertySettings, Page, Nothing, False, TabID, ModuleID, ModuleKey)
Dim objMailCustomFields As List(Of ContactFieldInfo) = ContactFormFields
Dim email As String = ""
' Assign values from from to mail custom field collection
For Each item As RepeaterItem In rptDetails.Items
Dim phValue As PlaceHolder = CType(item.FindControl("phValue"), PlaceHolder)
If Not (phValue Is Nothing) Then
If (phValue.Controls.Count > 0) Then
Dim objControl As System.Web.UI.Control = phValue.Controls(0)
For Each objContactField As ContactFieldInfo In objMailCustomFields
If (objContactField.ContactFieldID = Convert.ToInt32(objControl.ID)) Then
If (objContactField.FieldType = ContactFieldType.OneLineTextBox OrElse objContactField.FieldType = ContactFieldType.MultiLineTextBox) Then
objContactField.DefaultValue = CType(objControl, TextBox).Text
If (objContactField.Name = "Email") Then
email = objContactField.DefaultValue
End If
End If
If (objContactField.FieldType = ContactFieldType.DropDownList Or objContactField.FieldType = ContactFieldType.CustomField) Then
objContactField.DefaultValue = CType(objControl, DropDownList).SelectedValue
End If
If (objContactField.FieldType = ContactFieldType.MultiCheckBox) Then
Dim vals As String = ""
For Each i As ListItem In (CType(objControl, CheckBoxList).Items)
If (i.Selected) Then
If (vals = "") Then
vals = i.Value
Else
vals = vals & ", " & i.Value
End If
End If
Next
objContactField.DefaultValue = vals
End If
If (objContactField.FieldType = ContactFieldType.CheckBox) Then
Dim vals As String = ""
If CType(objControl, CheckBox).Checked Then
objContactField.DefaultValue = objContactField.Caption & " - true"
Else
objContactField.DefaultValue = objContactField.Caption & " - false"
End If
If objContactField.IsRequired Then
If Not (CType(objControl, CheckBox).Checked) Then
lblSubmitResults.Text = objContactField.Name + Localization.GetString("valRequired", Me.ResourceFile)
lblSubmitResults.CssClass = "NormalRed"
Exit Sub
End If
End If
End If
End If
Next
End If
End If
Next
If (email = "" Or email.Contains("@") = False) Then
email = PortalSettings.Email
End If
' Get the layout for subject and body
Dim objLayoutSubject As LayoutInfo = objLayoutController.GetLayout(Me.PropertySettings.Template, LayoutType.ContactEmail_Subject_Html)
Dim objLayoutBody As LayoutInfo = objLayoutController.GetLayout(Me.PropertySettings.Template, LayoutType.ContactEmail_Body_Html)
' Get the processed layout for subject and body
Dim phProperty As New System.Web.UI.WebControls.PlaceHolder
objLayoutController.ProcessItem(phProperty.Controls, objLayoutSubject.Tokens, CurrentProperty, CustomFields, objMailCustomFields, False)
Dim subject As String = RenderControlAsString(phProperty)
phProperty = New System.Web.UI.WebControls.PlaceHolder
objLayoutController.ProcessItem(phProperty.Controls, objLayoutBody.Tokens, CurrentProperty, CustomFields, objMailCustomFields, False)
Dim body As String = RenderControlAsString(phProperty)
phProperty = Nothing
Dim replyTo As String = PortalSettings.Email
If (PropertySettings.ContactReplyTo = ReplyToType.ContactPerson AndAlso email <> "") Then
replyTo = email
End If
Dim contactBCC As String = PropertySettings.ContactBCC
If (contactBCC.StartsWith("[CUSTOM:")) Then
Dim customField As String = contactBCC.Replace("[CUSTOM:", "").TrimEnd("]"c)
contactBCC = ""
For Each objCustomField As CustomFieldInfo In CustomFields
If (objCustomField.Name.ToLower() = customField.ToLower()) Then
If (CurrentProperty.PropertyList.Contains(objCustomField.CustomFieldID)) Then
If (CurrentProperty.PropertyList(objCustomField.CustomFieldID) <> "") Then
contactBCC = CurrentProperty.PropertyList(objCustomField.CustomFieldID)
End If
End If
Exit For
End If
Next
End If
Dim objContactLog As New ContactLogInfo
objContactLog.ModuleID = ModuleID
objContactLog.DateSent = DateTime.Now
objContactLog.SentFrom = replyTo
objContactLog.SentTo = MailTo
objContactLog.Subject = subject
objContactLog.Body = body
objContactLog.PropertyID = CurrentProperty.PropertyID
Dim fieldValues As String = ""
For Each field As ContactFieldInfo In objMailCustomFields
If (fieldValues = "") Then
fieldValues = field.Caption & ":::" & field.DefaultValue & "|||"
Else
fieldValues = fieldValues & field.Caption & ":::" & field.DefaultValue & "|||"
End If
Next
objContactLog.FieldValues = fieldValues
Dim objContactLogController As New ContactLogController()
objContactLogController.Add(objContactLog)
If Me.MailTo <> "" AndAlso replyTo <> "" Then
Try
DotNetNuke.Services.Mail.Mail.SendMail(replyTo, MailTo, "", contactBCC,
DotNetNuke.Services.Mail.MailPriority.Normal,
subject,
DotNetNuke.Services.Mail.MailFormat.Text, System.Text.Encoding.UTF8, body,
"", hostSettings("SMTPServer"), hostSettings("SMTPAuthentication"), hostSettings("SMTPUsername"), DotNetNuke.Entities.Host.Host.SMTPPassword)
'DotNetNuke.Services.Mail.Mail.SendMail(replyTo, MailTo, "", contactBCC,
' DotNetNuke.Services.Mail.MailPriority.Normal,
' subject,
' DotNetNuke.Services.Mail.MailFormat.Text, System.Text.Encoding.UTF8, body,
' "", PortalSettings.HostSettings("SMTPServer"), PortalSettings.HostSettings("SMTPAuthentication"), PortalSettings.HostSettings("SMTPUsername"), PortalSettings.HostSettings("SMTPPassword"))
lblSubmitResults.Text = Localization.GetString("EmailSent.Message", Me.ResourceFile)
lblSubmitResults.CssClass = "NormalRed"
Catch
lblSubmitResults.Text = Localization.GetString("EmailNotSent.Message", Me.ResourceFile)
lblSubmitResults.CssClass = "NormalRed"
End Try
Else
lblSubmitResults.Text = Localization.GetString("EmailNotSent.Message", Me.ResourceFile)
lblSubmitResults.CssClass = "NormalRed"
End If
For Each item As RepeaterItem In rptDetails.Items
Dim phValue As PlaceHolder = CType(item.FindControl("phValue"), PlaceHolder)
If Not (phValue Is Nothing) Then
If (phValue.Controls.Count > 0) Then
Dim objControl As System.Web.UI.Control = phValue.Controls(0)
For Each objContactField As ContactFieldInfo In objMailCustomFields
If (objContactField.ContactFieldID = Convert.ToInt32(objControl.ID)) Then
If (objContactField.FieldType = CustomFieldType.OneLineTextBox OrElse objContactField.FieldType = CustomFieldType.MultiLineTextBox) Then
objContactField.DefaultValue = ""
End If
End If
Next
End If
End If
Next
For Each objContactField As ContactFieldInfo In objMailCustomFields
objContactField.DefaultValue = ""
Next
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub rptDetails_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptDetails.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim objContactField As ContactFieldInfo = CType(e.Item.DataItem, ContactFieldInfo)
Dim phValue As PlaceHolder = CType(e.Item.FindControl("phValue"), PlaceHolder)
Dim cmdHelp As LinkButton = CType(e.Item.FindControl("cmdHelp"), LinkButton)
Dim pnlHelp As Panel = CType(e.Item.FindControl("pnlHelp"), Panel)
Dim lblLabel As Label = CType(e.Item.FindControl("lblLabel"), Label)
Dim lblHelp As Label = CType(e.Item.FindControl("lblHelp"), Label)
Dim imgHelp As Image = CType(e.Item.FindControl("imgHelp"), Image)
If Not (phValue Is Nothing) Then
If (objContactField.ContactFieldID = ContactDefaultFieldType.Email) Then
e.Item.Visible = Not Me.PropertySettings.ContactHideEmail
End If
If (objContactField.ContactFieldID = ContactDefaultFieldType.Phone) Then
e.Item.Visible = Not Me.PropertySettings.ContactHidePhone
End If
cmdHelp.Visible = Not PropertySettings.SearchHideHelpIcon
DotNetNuke.UI.Utilities.DNNClientAPI.EnableMinMax(cmdHelp, pnlHelp, True, DotNetNuke.UI.Utilities.DNNClientAPI.MinMaxPersistanceType.None)
If (objContactField.IsRequired) Then
lblLabel.Text = objContactField.Caption & "*:"
Else
lblLabel.Text = objContactField.Caption & ":"
End If
lblHelp.Text = Localization.GetString(objContactField.CaptionHelp, Me.ResourceFile)
imgHelp.AlternateText = Localization.GetString(objContactField.CaptionHelp, Me.ResourceFile)
Select Case (objContactField.FieldType)
Case ContactFieldType.OneLineTextBox
Dim objTextBox As New TextBox
objTextBox.CssClass = "NormalTextBox"
objTextBox.ID = objContactField.ContactFieldID.ToString()
If (objContactField.DefaultValue <> "") Then
objTextBox.Text = objContactField.DefaultValue
End If
objTextBox.Width = Unit.Percentage(100)
phValue.Controls.Add(objTextBox)
If (objContactField.IsRequired) Then
Dim valRequired As New RequiredFieldValidator
valRequired.ControlToValidate = objTextBox.ID
valRequired.ErrorMessage = Localization.GetString("valRequired", Me.ResourceFile)
valRequired.CssClass = "NormalRed"
valRequired.Display = ValidatorDisplay.Static
valRequired.ValidationGroup = ModuleKey
valRequired.SetFocusOnError = True
phValue.Controls.Add(valRequired)
End If
If (objContactField.Caption.ToLower() = "email") Then
Dim valRequiredEmail As New RegularExpressionValidator
valRequiredEmail.ControlToValidate = objTextBox.ID
valRequiredEmail.ErrorMessage = Localization.GetString("valValidateEmail", Me.ResourceFile)
valRequiredEmail.CssClass = "NormalRed"
valRequiredEmail.Display = ValidatorDisplay.Static
valRequiredEmail.ValidationGroup = ModuleKey
valRequiredEmail.SetFocusOnError = True
valRequiredEmail.ValidationExpression = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
phValue.Controls.Add(valRequiredEmail)
End If
Case ContactFieldType.MultiLineTextBox
Dim objTextBox As New TextBox
objTextBox.TextMode = TextBoxMode.MultiLine
objTextBox.CssClass = "NormalTextBox"
objTextBox.ID = objContactField.ContactFieldID.ToString()
objTextBox.Rows = PropertySettings.ContactMessageLines
If (objContactField.DefaultValue <> "") Then
objTextBox.Text = objContactField.DefaultValue
End If
objTextBox.Width = Unit.Percentage(100)
phValue.Controls.Add(objTextBox)
If (objContactField.IsRequired) Then
Dim valRequired As New RequiredFieldValidator
valRequired.ControlToValidate = objTextBox.ID
valRequired.ErrorMessage = Localization.GetString("valRequired", Me.ResourceFile)
valRequired.CssClass = "NormalRed"
valRequired.Display = ValidatorDisplay.Static
valRequired.ValidationGroup = ModuleKey
valRequired.SetFocusOnError = True
phValue.Controls.Add(valRequired)
End If
Case ContactFieldType.DropDownList
Dim objDropDownList As New DropDownList
objDropDownList.CssClass = "NormalTextBox"
objDropDownList.ID = objContactField.ContactFieldID.ToString()
Dim values As String() = objContactField.FieldElements.Split(Convert.ToChar("|"))
For Each value As String In values
If (value <> "") Then
objDropDownList.Items.Add(value)
End If
Next
Dim selectText As String = Localization.GetString("SelectValue", Me.ResourceFile)
selectText = selectText.Replace("[VALUE]", objContactField.Caption)
objDropDownList.Items.Insert(0, New ListItem(selectText, "-1"))
If (objContactField.DefaultValue <> "") Then
If Not (objDropDownList.Items.FindByValue(objContactField.DefaultValue) Is Nothing) Then
objDropDownList.SelectedValue = objContactField.DefaultValue
End If
End If
objDropDownList.Width = Unit.Percentage(100)
phValue.Controls.Add(objDropDownList)
If (objContactField.IsRequired) Then
Dim valRequired As New RequiredFieldValidator
valRequired.ControlToValidate = objDropDownList.ID
valRequired.ErrorMessage = Localization.GetString("valRequired", Me.ResourceFile)
'If (valRequired.ErrorMessage <> "") Then
' valRequired.ErrorMessage = valRequired.ErrorMessage.Replace("[CUSTOMFIELD]", objContactField.Name)
'End If
valRequired.CssClass = "NormalRed"
valRequired.Display = ValidatorDisplay.Static
valRequired.SetFocusOnError = True
valRequired.InitialValue = "-1"
valRequired.ValidationGroup = ModuleKey
phValue.Controls.Add(valRequired)
End If
Case ContactFieldType.MultiCheckBox
Dim objCheckBoxList As New CheckBoxList
objCheckBoxList.CssClass = "Normal"
objCheckBoxList.ID = objContactField.ContactFieldID.ToString()
objCheckBoxList.RepeatColumns = 1
objCheckBoxList.RepeatDirection = RepeatDirection.Vertical
objCheckBoxList.RepeatLayout = RepeatLayout.Flow
Dim values As String() = objContactField.FieldElements.Split(Convert.ToChar("|"))
For Each value As String In values
Dim objListItem As New ListItem
objListItem.Text = value
objListItem.Value = value
If (objContactField.DefaultValue <> "") Then
For Each v As String In objContactField.DefaultValue.Split("|"c)
If (v.Trim() = value.Trim()) Then
objListItem.Selected = True
Exit For
End If
Next
End If
objCheckBoxList.Items.Add(objListItem)
Next
phValue.Controls.Add(objCheckBoxList)
Case ContactFieldType.CheckBox
Dim objCheckBox As New CheckBox
objCheckBox.CssClass = "Normal"
objCheckBox.ID = objContactField.ContactFieldID.ToString()
Dim values As String() = objContactField.FieldElements.Split(Convert.ToChar("|"))
For Each value As String In values
Dim objListItem As New ListItem
objListItem.Text = value
objListItem.Value = value
If (objContactField.DefaultValue <> "") Then
For Each v As String In objContactField.DefaultValue.Split("|"c)
If (v.Trim() = value.Trim()) Then
objListItem.Selected = True
Exit For
End If
Next
End If
Next
phValue.Controls.Add(objCheckBox)
If (objContactField.IsRequired) Then
Dim valRequired As New CustomValidator
'valRequired.ControlToValidate = objCheckBox.ID
valRequired.ErrorMessage = Localization.GetString("valRequired", Me.ResourceFile)
valRequired.CssClass = "NormalRed"
valRequired.Display = ValidatorDisplay.Static
valRequired.IsValid = objCheckBox.Checked
valRequired.ValidationGroup = ModuleKey
valRequired.SetFocusOnError = True
'valRequired.ClientValidationFunction = "ValidateCheckBox"
phValue.Controls.Add(valRequired)
'Dim popupScript As String = "<script language='javascript'>" &
' "function ValidateCheckBox(sender, args) {" &
' "if (document.getElementById('<%=" & objCheckBox.ClientID & "%>').checked == True) {" &
' "page.IsValid = true;" &
' "} else {" &
' "page.IsValid = false;" &
' "}" &
' "}" &
' "</script>"
'Page.RegisterStartupScript("PopupScript", popupScript)
End If
Case ContactFieldType.CustomField
If (CurrentProperty IsNot Nothing) Then
If (CurrentProperty.PropertyList.Contains(objContactField.CustomFieldID)) Then
Dim objDropDownList As New DropDownList
objDropDownList.CssClass = "NormalTextBox"
objDropDownList.ID = objContactField.ContactFieldID.ToString()
Dim values As String() = CurrentProperty.PropertyList(objContactField.CustomFieldID).Split(Convert.ToChar("|"))
For Each value As String In values
If (value <> "") Then
objDropDownList.Items.Add(value)
End If
Next
Dim selectText As String = Localization.GetString("SelectValue", Me.ResourceFile)
selectText = selectText.Replace("[VALUE]", objContactField.Caption)
objDropDownList.Items.Insert(0, New ListItem(selectText, "-1"))
objDropDownList.Width = Unit.Percentage(100)
phValue.Controls.Add(objDropDownList)
If (objContactField.IsRequired And objDropDownList.Items.Count > 1) Then
Dim valRequired As New RequiredFieldValidator
valRequired.ControlToValidate = objDropDownList.ID
valRequired.ErrorMessage = Localization.GetString("valRequired", Me.ResourceFile)
'If (valRequired.ErrorMessage <> "") Then
' valRequired.ErrorMessage = valRequired.ErrorMessage.Replace("[CUSTOMFIELD]", objContactField.Name)
'End If
valRequired.CssClass = "NormalRed"
valRequired.Display = ValidatorDisplay.Static
valRequired.SetFocusOnError = True
valRequired.InitialValue = "-1"
valRequired.ValidationGroup = ModuleKey
phValue.Controls.Add(valRequired)
End If
End If
End If
End Select
End If
End If
End Sub
#End Region
End Class
End Namespace