Creating a Quiz Web application using SharePoint designer - Part 2

Welcome to Part two of this article. In part one we created the three lists that our application will use. In this part we we are going to build a page which shows a list of the available Quizzes and allows the user to click on one of them and begin the quiz. 

We will use the Data View Web Part (DVWP) and

work with paramters and system variables. Will will also be building a customised hyperlink to pass query string varibles to another web page depending on the user selection. 

 

Modifying Defult.aspx (the page to list our available Quizzes)

 

We will use our default.aspx page as the page to display our available Quizzes. Open the defult.aspx page in SharePoint designer. I would recommend you switch the view to 'Split' - that way you can see the code and the design which makes for a great way of seeing the code as it is being created.

 

Inserting our Data View

 

Our default page will contain a single Data View Web Part that lists all the available Quizzes and provide a hyperlink for each to begin the Quiz. Effectively we are just listing all the list items contained in the Quiz list.

Follow these steps to insert the Data View Web part:

1. Select the area on the page where you want to insert the view (there may a “click here to insert a Web Part” showing on the screen already)

2. On the top menu go Data View | Insert Data View

3. In the top right task pane, select the Data Source Library tab

4. Select the Quiz list and select Show Data

You can now see a list of all the available data fields that you created (and some system created) in the Quiz list.

5. Using Control & Click select: Title, Description, Pass Mark and NumberOfQuestions

6. Click “Insert selected Feilds as...” button ( just above the list of fields and choose “Multiple item view”

 

This gives us a DVWP showing all our available Quizzes.

 

What is an OOUI?

 

You will notice if you click on a table area or entry you get a  button – this has the friendly title of a On Object User Interface  (OOUI) but is actually an incredibly useful helper in everything you want to do in SharePoint.

For example, to change the Pass Mark cells to show as formatted percentage values, click on the first value and then click the button. If you then select “Number formatting options” you can select “Percentage %”.

The Data View Web Part has its own mega-OOUI at the top right of the table which allows you to control all its functions (we will get right into this later).

 

 

 Grabbing System Variables

 

In this application we are going to require the name of the currently logged in user and also the current system time and date. Both these variables are system variables and can be easily accessed in SharePoint. Most of the work is already done for us as they are actually almost available. Switch to the code view and find the <ParameterBindings> section near the top of the page.

You should see something like this:

<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>

UserID and CurrentTime are already there for us to use. We just need to add a couple of extra lines so that we can use them in our form.

 

Click on the DVWP so that the whole part is highlighted, in the code view all of the associated code should also be highlighted. Towards the top of the highlighted code you will a line containing the following:

<xsl:param name = “dvp_apos”>&apos;</xsl:param>

Directly below this add the following two lines

<param name = "UserID">

<param name = "Today">

Note: We are using XSLT here which is case-sensitive! (There is much more on XSLT to come later).

This makes the current user information (for example ‘DOMAIN\Username) available to use and also the current date and time both passed as parameters into the form. These are pretty useful for lots of application work.

 

Creating a Unique session ID

 

The Answers list will contain every answer given for every exam for each time it is taken. When a new Quiz is started by clicking its title off the default.aspx page we want to create a unique identifier for the set of answers. This session ID will allow us to group together the answers.

I tried a few options and decided on adding the current date and time together with the Username to form a string. Although this isn’t a true GUID it should work well as an identifier for our needs.

 

We already have the UserID and Today parameters available to us so all we need to do is to create another parameter to store our Session Parameter.

Add the following line directly below the other two lines you just added:

<xsl:param name="Session" select="concat($Today,substring-after($UserID,'\'))"></xsl:param>

Let’s break down the line below:

Section

Explaination

xsl:param name="Session”

In our XSL style sheet, create a new Variable called session. This can be referenced by calling $Session

Concat(

Concatenate (join) two strings to form a single string.

$Today

The current time and date parameter stored as $Today

substring-after($UserID,'\')

The substring-after function chops the $UserID variable at the ‘\’ which removes the domain name from the $UserID string.

 

Our session variable will end up looking something like this ‘2009-04-06T05:13:05ZUserName’

 

 

We have now created our Session parameter and we are ready to create our hyperlink that will initiate the quiz.

Before we create the link let’s quickly create the new ASPX page that we are going to link to:

 

  1. From the main menu select File | New and choose ASPX page.
  2. Then File | Save As and save the page as “ShowQuestion.aspx
  3. Close the page

 

We are going to create our hyperlink linked to the title of each quiz in the list, and we are going to pass the following variables via a query string into the ShowQuestion.aspx page:

 

Paramter

Description

Title

Exam Title

Question

The number of the question to display

Of

The total number of questions in the quiz

Session

Unique session ID for the attempt at the quiz

 

Here are the steps to create our hand-built hyperlink with parameters:

 

1. Click on the title of the Quiz in your Data view Web Part table

2. Click of OOUI button

3. Change the Format as: to Hyperlink

4. Select Hyperlink options

1. For the Address: Browse to our newly created ShowQuestion.aspx page

2. Hit the Parameters button

3. Hit the Add Button

The Add Parameter box will pop up asking for a name and value. To add our “Title” parameter give the name as “Title” and then scroll down the list of values and find the Title field like this:

Important note: Check that SharePoint designer hasn’t added a @ at the start of the name of your parameter – if it has just delete it so that the name is “Title”.

 

 

To add our “Question” parameter, click add again. This time give the title as “Question” and type the value as “1” (without the quotes).

 

Then Add our “Of” parameter (which is the total number of questions) by giving the title as “Of” and the selecting the value from the drop down list as “NumbeOfQuestions”)

 

Our final parameter is the Session ID we created earlier, although this isn’t available from the drop down list we can still reference it. Hit add one more time and give the title as “Session”. For the value enter {$Session}

SharePoint Designer knows that anything enclosed in {} is a system field. A “$” means a parameter and “@” maps to a node variable. We will be getting lots of practice in using {$variables} on our next ASPX page!

 

You should now have all your parameters added and the screen will look like this:

 

 What did we just do? We have added a number of paramters to our hyperlink which will be added at the end of the link as a query string. The Title variable was assigned to a node value, identified as {@Title}. The Question number was set to equal '1' as we always want to start with the first question. The Of value was set to 

the node value of the NumberOfQuestion. Finally the Session value was assigned the value of a paramter, idenfitied by {$parameter-name}.

If you save your default.aspx and then view it in your website when you hover of the title of an exam you should now be able to see your link. If you click the link you will be taken to our blank ShowQuestion.aspx page and you can see all four variables have been passed across in the query string.

 

In part three of this article we will build the ShowQuestion.ASPX page which will show each Question and get an answer from the user (and mark the question).

[Part 1][Part 2][Part 3][Part 4][Part 5]

Comments

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    You did a very nice job i fix byronzhu  & PascalF problem add this paramter <ParameterBinding Name="LogonUser" Location="ServerVariable(LOGON_USER)"/>   <xsl:param name="LogonUser"/> and for seesion <xsl:param name="Session" select="concat ($Today,substring-after($LogonUser,''))"></xsl:param>  

  • Anonymous
    January 01, 2003
    This is such a great exercise. I too was having problems getting the Server Variable parameter to work. "you have to enable Integrated Windows Authentication in order that it will work: MMC --> right click your website --> properties --> Directory Security --> Edit anonymous access and authentication control --> tick the checkbox on bottom saying "Integrated Windows Authentication" --> OK --> Apply"--http://www.infoqu.com/127853-1-server-variables-not-working.html For the Custom Hyperlink section, I found I had to do this to get the title name to show up; otherwise it came up as "Untitled1." <a href="ShowQuestion.aspx?Title={@Title}&amp;Question=1&amp;Of={@NumberOfQuestions}&amp;Session={$Session}"><xsl:value-of select="@Title"></xsl:value-of></a&gt; Use the XSL value-of reference to pull the Title variable.

  • Anonymous
    January 01, 2003
    As soon as I input the code below, I get an error "This web part does not have a valid XSLT stylesheet:  Error:Endtag 'xsl:stylesheet' does not match the start tag 'param'.  I don't know how to fix.

  • Anonymous
    January 01, 2003
    This is a great post, I really appricate the level of detail and explanations you have included.  I am having a problem where where my title for the Quiz is showing up as "Untitled 1".  The link works correctly, I just can't seem to find what I did wrong with the Hyperlink.  I believe it was showing the correct name before I add the link.  Thanks.

  • Anonymous
    January 01, 2003
    In our environment anyway the "CurrentUserName" that's getting bound to "UserID" and pulled is as an XSL param is actually Lastname, Firstname.  That's why the string function that is expecting domainuser ends up returning an empty string.

  • Anonymous
    January 01, 2003
    I still can't get the UserID to show up in the session variable.  I added the Logon data above - can anyone help me?  My data is below: Parameter: <xsl:param name="dvt_apos">'</xsl:param> <xsl:param name = "UserID"></xsl:param> <xsl:param name = "Today"></xsl:param> <xsl:param name = "LogonUser"/> <xsl:param name = "Session" select="concat($Today,substring-after($LogonUser,''))"></xsl:param> <xsl:variable name="dvt_1_automode">0</xsl:variable> ******** Parameter Bindings ********** <parameterbindings>  <ParameterBinding Name="ListID" Location="None" DefaultValue="{7A182949-05CD-452B-9769-B52480A99946}"/>  <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>  <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>  <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>  <ParameterBinding Name="LogonUser" Location="ServerVariable(LOGON_USER)"/>   </parameterbindings></WebPartPages:DataFormWebPart>

  • Anonymous
    January 01, 2003
    When copy and paste the below code, encounter error <param name value="UserID"> <param name value="Today"> So I had to change them to <xsl:param name="UserID" /> <xsl:param name="Today" /> Your artical is very useful for me, Thanks.

  • Anonymous
    January 01, 2003
    Hi, I am using SharePoint 2010 designer, here i am not able to find any of these lines in my page. <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/> <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/> <xsl:param name = “dvp_apos”>&apos;</xsl:param> Can any of u can help me on this.?

  • Anonymous
    September 20, 2010
    Quoted Text:  This is a great post, I really appricate the level of detail and explanations you have included.  I am having a problem where where my title for the Quiz is showing up as "Untitled 1".  The link works correctly, I just can't seem to find what I did wrong with the Hyperlink.  I believe it was showing the correct name before I add the link.  Thanks.


To resolve,  in Sharepoint designer on the page when you add your parameters, add {@Title} in the 'Text to display' field at the top.

  • Anonymous
    September 28, 2010
    i get the value as none while trying to configure it to hyper link

  • Anonymous
    January 24, 2011
    I had similar issues as above:   The UserName was not being recognized in the Session, I changed the code from: <xsl:param name = "dvt_apos">'</xsl:param> to the following: <<xsl:param name="dvt_apos">&apos;</xsl:param> in the default.aspx page, and everything worked.

  • Anonymous
    January 25, 2011
    hi , I am unabling to hide the   CorrectAnswer   Exam   QuestionNumber   SessionID give me the solution

  • Anonymous
    January 25, 2011
    Raj, You can do the following to hide the text boxes: Highlight each field, then in the 'Tag properties' pane (bottom left) find the 'Visible' Attribute and set it to false.

  • Anonymous
    January 26, 2011
    Hi Linz, After completion  of my questions in my quiz , I pressed submit button it will showing Results page but the appearing output ' Required score' is in Green but no output will dislpays in  'Your score'.my result is not connected to results page ,pls tell me solution..      thanking you,

  • Anonymous
    February 01, 2011
    How to enable the quiz timing like after some time the quize has to get disabled/session out from the quiz..any idea....pls help

  • Anonymous
    February 24, 2011
    Can the questions appear randomly? I have a need that could appear on the quiz 10 questions, but a bank of 100 words. each user does not receive the same questions.

  • Anonymous
    March 01, 2011
    hi , This is a great post, I really appricate the level of detail and explanations you have included. I am unabling to hide the   CorrectAnswer   Exam   QuestionNumber   SessionID give me the solution and in part 5 it is showing for all the users result but we need only for indiv user score want to disply plz help on this kindly send the details to my mail id is 06santhoshv@gmail.com

  • Anonymous
    March 01, 2011
    HI  Linz Thanks for giving the solution for hide the fields. Another Problem is In part 5 it is showing for all the users result but we need only for indiv user score want to disply plz help on this ......

  • Anonymous
    November 09, 2011
    McKTech 5 Aug 2009 12:41 PM # As soon as I input the code below, I get an error "This web part does not have a valid XSLT stylesheet:  Error:Endtag 'xsl:stylesheet' does not match the start tag 'param'.  I don't know how to fix. How did you correct this?

  • Anonymous
    December 20, 2011
    Not able to add Filter Question Number on Question Datasource as soon as i add i will get the below error The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again. If the problem persists, contact the server administrator. Even the output paramaeter is added i am using Sharepoint Designer 2010

  • Anonymous
    February 27, 2012
    Anyway to get these pages and lists exported so we can import into SharePoint 2010?

  • Anonymous
    May 16, 2012
    Very nice post i am having the following issues http://jaspoint01:8080/sites/SLJHRD/Leave%20Requisition%20Portal/SLJQUIZ/SitePages/ShowQuestion.aspx?Title=&Question=1&Of=&Session=2012-05-16T10:00:58Zdb5789 The Title and Of  are both passing blank when I click the list item. Not exactly sure what could cause that. Any suggestions

  • Anonymous
    June 18, 2012
    Like Padmaraj, I can't find the userID parametrs of <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/> Any advice on where this might be found/stored? Thanks!

  • Anonymous
    February 12, 2013
    when i try to write the code : <xsl:param name="Session" select="concat($Today,substring-after($UserID,''))"></xsl:param> it didn't work, it shows that "in xhtml 1.0 strict the tag <xsl:param> is not permited? besides, when i wanna add parameter the tittle with parameter hyperlink, the button UUOI didnt show when i click the title, so how can i add hyperlink parameter and modify it? any advice? thanks, im newbie in Sharepoint Designer 2010

  • Anonymous
    November 15, 2013
    This entire page I am lost. I keep starting over thinking i forgot something but still don't understand and get lost. The codes that are suppose to be on the page ar not there....

  • Anonymous
    December 05, 2013
    Is there anyway this can be updated for SharePoint 2010 because some codes are not working. I got all the way to part 3 and my link from quiz to showquestions.aspx don't link. I don't think what I am doing wrong. I did the filter by the book. Someone please help me

  • Anonymous
    May 27, 2014
    I, too, have the same issue as Padmaraj. The following do not exist in the default code:





    I do see a parameter binding that lists "idPresEnabled", would that be for the user ID? I am on a closed network that utilizes a smartcard to present PKI credentials to the system and network.

    Thanks,
    Tom (am3r1can@outlook.com)

  • Anonymous
    February 13, 2015
    The comment has been removed

  • Anonymous
    February 18, 2015
    @sb4964, @EMaat

    The reason it is coming up as “Untitled 1” is because when you create the link before you hit ok look at the top of the link window, there is text there that you can set for the hyperlink, the default is “Untitled 1” Just change it there and it will update the code correctly. You can do an edit to the hyperlink as well and change it there or in the code as @sb964 did to make it more dynamic to the name of the Quiz.

  • Anonymous
    June 08, 2015
    Is this possible without SharePoint designer? I have done the QUIZ, QUESTION, and ANSWER lists. I have a feeling it's just a lot of lookup, but I am stuck at what's next after creating the list with questions

  • Anonymous
    July 31, 2015
    Is there a similar description how to create a quiz web application in Share point 2013?