|
phdcc.Data DNN modules |
| phdcc.Data.View: Overview |
phdcc.Data.View is a DNN 4 module to display a single result produced by a form created using the phdcc.Data.Form module.
phdcc.Data.View contains a wizard that creates a simple template that displays the result. The template is a standard ASP.NET user control in a file - you can edit this to customise the output so that it appears as you wish.
Note carefully that module users with Edit permissions (ie Administrators etc) can enter ASP.NET code that is then run - therefore be very careful to whom you give Edit permissions.
Form values for SuperUser users such as host are not returned.
If you output any information that a user provided, please remember to make it HTML safe by calling Server.HtmlEncode().
So phdcc.Data.View is primarily aimed at showing the answers to the questions posed in one form. For a 'Profile' form, phdcc.Data.View can also show results from other forms that the user has filled in. In addition, any other (per-user) data can be shown, eg from information stored by DNN or other third-party modules.
To use phdcc.Data.View:
There are also these further options - selected in Settings:
Click on the Settings button (or select Settings from the module menu). Expand the phdcc.Data.View section and choose/enter these values:
DesktopModules\phdcc.Data.View directory.Click on Update to save your changes.
(Please do not put two forms with the same Form Id on the same DNN page - phdcc.Data.View does not know how to distinguish between and so will send you to the Settings page.)
A template is needed to define what is displayed for the chosen result.
An initial template can be set up for you by a phdcc.Data.View wizard.
You can then tailor it to fit your precise requirements within Edit Template.
Alternatively you can upload your own template using FTP or [Admin][File Manager]
into the DesktopModules\phdcc.Data.View directory, and then select it in Edit Template.
A template is a standard ASP.NET user control file that can contain both HTML and code, either VB or C# -
see examples below.
Use a separate file for each of your templates, ie for each different instance of
the phdcc.Data.View module on your site.
When you first enter Edit Template, click on "Create a new template using a wizard":
(Alternatively, you can click on "Choose a different template" to pick an existing template or
one that you have uploaded to the DesktopModules\phdcc.Data.View directory.
Templates must start with precisely the correct text, as described below.)
Enter a filename for your template, then click on "Create template file using a wizard".
After this, you will need to confirm that you want the file created.
A template is created that contains all the questions on your form.
The template is laid out in a table, with group name on the left, questions and answers in the middle.
Note that by default, results for email type questions are replaced
with EMAIL SUPPRESSED; you can change the code to show the email if you wish.
The generated template is now shown in an edit box. Edit this as required and then press Update.
This a result displayed by phdcc.Data.View using the above template:
The "Create a new template" wizard creates a template user control file with the correct code at the start. When editing within Edit Template, you do not see this initial code. However, if you create your own template user control file from scratch, you must make sure that the correct code appears at the start. For Visual Basic, this is:
<%@ Control Language='VB' ClassName='ControlName' Inherits='phdcc.Data.View.TemplateBaseVB' CodeFile='TemplateBase.ascx.vb' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet() %>
where ControlName corresponds to the template filename with ".ascx" removed. For C#, the correct initial code is:
<%@ Control Language='C#' ClassName='ControlName' Inherits='phdcc.Data.View.TemplateBaseCS' CodeFile='TemplateBase.ascx.cs' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet(); %>
The template shows a single result. Your template code can be in either Visual Basic (VB) or C-Sharp (C#). The template can contain any HTML and use all normal ASP.NET code. However it will typically use various phdcc.Data.View helper functions to access form results. The "Create a new template" wizard uses the Form and FormValues helper functions.
The following VB code is in a file called ShowProjectVB.ascx so that it matches
the chosen ClassName property (without the extension).
The filename must not start with a number and should not contain periods and spaces.
The code starts with the required standard lines.
<%@ Control Language='VB' ClassName='ShowProjectVB' Inherits='phdcc.Data.View.TemplateBaseVB' CodeFile='TemplateBase.ascx.vb' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet() %>
<h1>Project details:</h1>
<p>
<b><%=Form("idPP_Name")%></b><br />
<%=Form("idPP_Description")%>
</p>
This code calls the phdcc.Form.View SetResultSet function to get the results that we want to look at.
This code then contains some HTML with a couple of calls to the phdcc.Form.View Form function to return the answers to two questions: those with a QuestionId of "idPP_Name" and "idPP_Description".
The C# equivalent code is very similar, in a file with matching filename ShowProjectCS.ascx
<%@ Control Language='C#' ClassName='ShowProjectCS' Inherits='phdcc.Data.View.TemplateBaseCS' CodeFile='TemplateBase.ascx.cs' AutoEventWireup='true' %>
<%@ Import Namespace='phdcc.Data.View' %>
<% SetResultSet(); %>
<h1>Project details:</h1>
<p>
<b><%=Form("idPP_Name")%></b><br />
<%=Form("idPP_Description")%>
</p>
The following phdcc.Data.View properties and functions can be called from your code.
All the Form... functions that return strings are HTML safe.
For FormValues and FormXValues,
make sure that you call Server.HtmlEncode() on any user provided data.
Functions marked *** are only usable on results from 'Profile' forms.
If the user did not answer a question, then Nothing is returned, unless you have specified a default value
(or called SetShowBlankFormValues(True)).
The phdcc.Data.View.ResultInfo class has these properties:
The phdcc.Data.View.ResultSetInfo class has these properties:
The following code shows how to use more of the phdcc.Form.View functions in VB. The code follows the rules given above: it does not use Response.Write, and it sets server control properties before the control is declared.
<table>
<tr>
<td>
<%
Dim PhotoPrimary As String = FormX("idPhoto", "id7PhotoPrimary")
If Not PhotoPrimary Is Nothing Then
imgPrimaryPhoto.ImageUrl = PhotoPrimary
Else
imgPrimaryPhoto.Visible = False
End If
%>
<asp:Image ID="imgPrimaryPhoto" runat="server" Width="100%" />
</td>
<td>
<%
For Each ri As ResultInfo In FormXValues("idProjectProfile", "idHelpType")
blHelpType.Items.Add(ri.ResultValue)
Next ri
%>
<asp:BulletedList ID="blHelpType" runat="server" />
</td>
</tr>
</table>