次の方法で共有


Creating a Quiz Web application using SharePoint designer - Part 4

Welcome to part 4 where we will complete the creation of our ShowQuestion.aspx page. In this part we will add a custom list form to capture the input from the user. We are going to populate our Answers list with values taken from the user, the Questions list (as well as Query string and system variables!). We are also going customise the 'Submit' botton of our form.

Adding in our Answers custom list form

 

We now have our Question displaying nicely on our ShowQuestion.aspx page and we are ready to ask the user to choose their answer. We are going to use our second Web Part Zone which we named “Answers”.

This time we aren’t displaying information, rather we are asking the user for input. To achieve this we are going to use another Part, a custom list form.

The user will add a value into the Answers table (into the ChosenAnswer field) and we will also pass some of the values from the Question table into the Answers table so that we can determine if the answer is correct or not. We will also pass the query string value Session into each answer so that all the answers will form a set so we can display a final mark for the whole exam.

Firstly, let’s add in our custom list form:

· Highlight the “Answers” Web Part Zone

· From the menu select Insert | SharePoint Controls | Custom list form

The list to use will be “Answers”, content type is “Item”. Make sure the form is set to “New Item Form” and de-select “Show Standard toolbar”

· Click “Ok”

A big and ugly form appears in our second Web Part Zone. The only field the user can change (and actually the only one we will let them see) is the AnswerGiven filed. All the others are used in the background to make the application work. Here is an explanation of how we will use them:

 

 

Field Name

Type

Title

We will store the User ID in here ($UserID system variable)

AnswerGiven

The user will choose either A,B, C, or D from a dropdown box

CorrectAnswer

We pass the correct answer from the Question DVWP into here

Exam

We pass Exam title from the Title query string parameter

QuestionNumber

We pass Question number from the Question query string parameter

SessionID

We pass Session ID from the session query string parameter

MarkAnswer

When the item is saved this calculated field will become a ‘1’ if the answer given matches correct answer , otherwise it is set to zero 

 

So, the plan is to load the form with values that actually come from no less than four different sources: The user input, Query string values, server values and also values from another web part (the Questions DVWP). For the time being we will leave all these fields visible so we can see what is going on.

 

Pre-loading form fields from Query string variables

 

As I mentioned we are going to load three of our form fields from query string variables, title, question and session.

The first thing we need to do is define the parameters so the form can use them. To do this:

1. Click on the OOUI button  of the Custom list form web part and click on “Parameters”

2. Hit “New Parameter”

3. Name=Quiz

4. Source=Query String

5. Query string value = Title

6. Default value =*Quiz* (you don’t need to add a default value but it is useful to see it in the form)

Next the question number

1. Hit “New Parameter”

2. Name=Question

3. Source=Query String

4. Query string value = Question

5. Default value =*Question*

Then the “Of” parameter which stores the total number of questions in the Quiz. We will not be passing this value into any of the form fields but we will be using it at the end of this section.

1. Hit “New Parameter”

2. Name=Of

3. Source=Query String

4. Query string value = Of

5. Default value =*Of*

 

And finally the session ID

1. Hit “New Parameter”

2. Name=Session

3. Source=Query String

4. Query string value = Session

5. Default value =*Session*

 

 

We will now be able to reference these parameters in our custom list form. Here is how to load the value of a parameter into a field.

In the form find the QuestionNumber field and click on the input box. You will see a OOUI button appear, follow these steps:

1. Click on the OOUI for the input box

2. You will see the following dialog box appear

At the moment the field type is formatted as a “List Form Field” which means it cannot be manipulated. Click on the drop down selector and change to “Text Box”

This simple action is the key to opening up a lot of things you can do with forms and data views – it allows us to ASP.NET so we can create values and apply validation amongst other things.

 

1. Click again on the input box associated with the Question Number

2. On the bottom left hand task pane (Tag Properties) find the Text Value

3. Enter the following value into the Text property {$Question}

 

What did we just do? Firstly we created some parameters (Question, Quiz and Session) by grabbing them from the query string. We then changed one of the fields in our form so that it was a TextBox. This allows us to pass parameter values into the field. By enclosing the text in” { }” the designer knows it’s a value and a “$” means it’s a parameter.

If you like at this point you can save your page and take a look at it in the browser. You should see the value of the Question parameter in the query string be passing into your form.

We now need to do the same with the session and Quiz parameters.

Change the format on the input boxes on the SessionID and Exam fields to be TextBox. Then, for the Text value of session add {$Session} and for the Text value of Exam add {$Quiz}.

All three query string values should now be added into your form (you can check in your browser to see them all setting there ready to go).

 

Pre-loading form fields from values in another web part

 

We now have the values from the Query string placed into our form and now we are going to load some of the fields by passing a value from the Questions data view web part.

We need to send the data we want from the Questions web part to the Answers web part. Here is how:

1. Select the OOUI of the top, Questions, web part.

2. Select “Web Part Connections...”

3. Action: Send row of data To

4. Connect to a Web part of this page

5. Target: Answers

6. Action: Get Parameters from

We have specified that we are going to send some of the fields from the Questions part in to the Answers part. We have also said that when they are sent into the Answers part, they will be available as parameters.

 

Scroll down the list until you see the <Create a new parameter> section.

Here is how to create our two new parameters:

1. Click on the <none> section next to the <Create a new parameter>

2. This opens the Parameters box, call the first parameter “CorrectAnswer” and click OK

 

Now we need to link the fields in the Questions list to our new parameters. Here is how.

 

1. Click on the <none> column next to the “CorrectAnswer” column that you created

2. From the dropdown select the field CorrectAnswer

Click, Next, Next then finish and we are ready to load these values into our custom list form.

First we need to change the format of CorrectAnswer input box from a form field to Text Box. To do this click on the input box and click the OOUI button, from the format drop down, select Text Box, like this:

 

 

Secondly we need to place the parameter values into the next box fields. This is done the same way as we loaded the query string values.

Click in the CorrectAnswer text box and change the Text value (in the properties task pane on the left hand side) to {$CorrectAnswer}

 

 

What did we just do? We connected the Questions web part to the Answers web part so that we could send some of the fields across as parameters. We then loaded the values of a the passed parameter into a textbox by using {$parameter-name} as the format.

Take a look at the form in your browser and you will see all our new variables populated into our list form.

 

Loading a system variable (current user name) into a custom form

 

Finally, we have one more field that we are going to load into the form. This will be the system variable for the current user name. You will recall how we get this variable from earlier in the article, this time we are going to chop our the domain and then store it in our Title field.

This field is useful if you want to store or sort the Quiz results or answers by a particular user.

Firstly we need to add a couple of lines of code at the top of the XSL style sheet. Find the start of the style sheet for the Answers web part . You should see all the <xsl:param name=...> definitions for the parameters we have created.

Add the following lines:

<xsl:param name="UserId"></xsl:param>

<xsl:param name="UserName" select="substring-after($UserId,'\')"></xsl:param>

 

The first line makes the UserID system variable available. The second line created a new parameter UserName which has the domain removed.

 

We are now ready to load this value into the Title input field. Convert the field format from a list field type to a Text Box then load {$UserName} into the Text properly of the field.

 

Take one final look at your form in the browser – all our fields are now loaded into the form correctly. We are nearly there! Obviously we will hide the fields a little later but for the moment let’s think what we need to happen for this page to function as a real quiz application.

So far we have displayed the first question correctly, we now want to get the answer from the user and let them submit it. When the answer is submitted we need a few things to happen automatically:

 

· A new Answer list item has to be created with to store the User’s response

· The IsCorrect field to be set to a ‘1’ if the answer is correct

· We then need to display the next question OR if we have just completed the last question in the Quiz then show the final results

All of the above is actually very easy indeed thanks to SharePoint designer. In fact as our custom list form is already linked to the Answers list a new list item will automatically be created and the IsCorrect field will be populated using the formula you entered when you created the list – so the first two bullets are already completed!

 

 

In order to get full control over what happens when we submit the form we are going to build our own “Submit” button. Here is how:

1. On your current form, delete the existing “OK” and “Cancel” buttons at the top and bottom of the form

2. In the top right task pane, choose the “Toolbox” Tab

3. Scroll down to the “Form Controls” section

4. Drag a “Input (Submit)” button in to your form

We now have a new Submit button in our form, next we need to associate some actions to the form “Submit” button. Namely we want to submit the data and then redirect the page to show the next Question (or results page). Here is how:

1. Right click on the button and select “Form actions”

2. Highlight “commit” and then click “Add”

3. Highlight “Navigate to a page” and then click “Add”

4. With “Navigate to page” highlighted, hit “Settings”

5. Hit the “Browse” button and select our ShowQuestion.aspx page

At this point our button will submit the data to the form and then redirect us back to the ShowQuestion form. That is all good but we need to display the next question rathen than returning to the current one. To do so, we need to pass on all the parameters (The quiz title, the Session and the amount of questions in the quiz) and we also need to show the next question in the Quiz by incrementing the Questions parameter.

You may have noticed a “Parameters” button available to use as part of the settings on the "Navigate to a page" action – unfortunately this is one example where try as it might, SharePoint designer can’t help us.

 

If you take a look the code behind the button you will see the following:

<input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={ShowQuestion.aspx}')}"

The button is using Javascript and the redirect is a part of the string. If we let SharePoint designer try and insert our parameters they will be passed as literal values (i.e. Question will not show as ‘1’ it will show as @Question) and our query string will break.

 

In order to overcome this we need to get down into the code and build our string for a custom redirect.

 

Building a custom string to pass multiple parameters into form re-direct

 

We are going to build a string containing all our parameters that can be used in the JavaScript.

First locate the XSL style sheet section for the Answers section. It should look something like this:

 

<xsl:stylesheet

...          

       <xsl:param name="dvt_apos">'</xsl:param>

       <xsl:param name="ListItemId">0</xsl:param>

       <xsl:param name="ListID">{BF902FA5-F0D4-4A51-BA62-C08AB807F4DA}</xsl:param>

       <xsl:param name="Quiz">*Quiz*</xsl:param>

       <xsl:param name="Question">*Question*</xsl:param>

     ...

       <xsl:variable name="dvt_1_automode">0</xsl:variable>

 

At the bottom of this section add the following lines:

<xsl:variable name="URL1"><xsl:value-of select="$Quiz"></xsl:value-of></xsl:variable>

<xsl:variable name="URL2"><xsl:value-of select="$Of"></xsl:value-of></xsl:variable>

<xsl:variable name="URL3"><xsl:value-of select="$Session"></xsl:value-of></xsl:variable>

 

This passes the values of our query string values into XSL variables so they can be passed into the Java script. You may have noticed that we haven’t dealt with the $Question parameter – this is because we are going to do something a little extra with this value.

We want to take the $Question query string parameter and increment the value so that when we direct our page the next question in the sequence will be displayed (remember that the Question Data View Web part is set to filter all but the current Question value).

Fortunately XSL has maths functions available so we just need to create one last XSL variable and add one to it. We need to place this variable inside the body of the form so that it is in scope. Follow these steps:

Locate the XSL template for the main body of the table, it will begin with:

 

<xsl:template name="dvt_1.body">

<xsl:param name="Rows"/>

...

 

Add the following line which increments that value of the $Question query string parameter and places the value in the XSL variable called NextQNumber

<xsl:variable name ="NextQNumber" select="$Question +1"></xsl:variable>

 

That is all our variables created, we can add them all together into a string so they can be used to make our submit form button re-direct to our ShowQuestions.apsx page which multiple parameters.

 

Build our button

 

To do this click on the submit button so that it’s code is highlighted. Currently it’s associated code will be:

<td width="99%" class="ms-toolbar" nowrap=""><IMG src="https://blogs.technet.com/_layouts/images/blank.gif" width="1" height="18"/><input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={ShowQuestion.aspx}')}" /></td>

 

It is the __redirect= section that I have highlighted that we are interested in, we want to insert our string here so that we can pass our parameters.

 

Change the whole string to be as follows (I have highlighted the new section).

input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question='

,$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}"/>

 

What have we done here? It looks complex (and admittedly it is a little fiddly) but actually all we have done is pass the query strings into XSL variables and use the concat function to build a string that the Javascript function is happy with.

 

Try testing this in your browser – you will see that when you submit the answer to a question then the next question in the quiz is automatically shown(and we have preserved all our query string variables).

 

By the way, take a look (in your browser) at the contents of the Answers list. You will see a new list item for each answer that has been submitted. We will tidy up this view later.

 

What happens when we get to the last Question?

 

With the code so far we can select a Quiz from our default.aspx page and then answer each question in turn.

 

However, currently when we run out of questions our quiz will just keep running. We want the form to re-direct to show the results when the final answer is submitted by the user. Luckily there is a nice easy way of doing this.

We will use conditional formatting to compare the current question number (stored in the query string $Question) to the number of questions in the quiz (stored in the query sting $Of ).

Here is how to do it:

1. Right click on the “Submit” button and select “Conditional formatting”

2. The Conditional formatting task pane will appear at the top right

3. Click “Create” and “Hide Content”

4. Click the “Advanced” Button

5. Enter the following expression “$Question = $Of” (without the quotes)

6. Click Ok, Ok.

 

 

So when our $Of value is the same as our $Question value Ii.e. we are on the last question) the button will disappear!

In order to get the user to see the results of the Quiz (i.e. the score and pass / fail) we want to jump to our ShowResults.aspx page when they have submitted the final answer. To do this we will add another submit button that will only appear when it is the final question in the Quiz. As far as the user is concerned it looks like the same button.

Here is how:

1. Click in the space to the right of your existing “Submit” Button

2. Located the Toolbox task pane from the tabs in the top right

3. Drag a “Input (Submit)” button to sit next to your existing button, like this

 

4. Create a blank results page by File | New | ASPX Page and save it as “ShowResults.Aspx”

5. Switch back to your ShowQuestion.aspx page and right click on your second button

6. Select Form actions

7. Select “Commit” and Click Add

8. Select “Navigate to a page” and click Add

9. Hit “Settings”

10. Browse to your new ShowResults.aspx page

11. Ok, Ok, Ok.

We are nearly done, we just need to add a couple of parameters to our second button. This is much more straightforward this time as the variables have already been created and we only need to pass the Quiz and Session values across this time as we no longer care about the question number.

 

Click on your second button so that the code is highlighted and change the following string from

<input name="Submit2" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={ShowResults.aspx}')}" /></td>

 

To this

<input name="Submit2" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit

;__redirect={ShowResults.aspx?Title=',$URL1,'&amp;Session=',$URL3,'}'))}" />

The above change passes the Quiz Title and the Session parameters to our ShowResults.ASPX page. Finally we only want this button to show on the last question in the Quiz (and when the other button is hidden). To do this we need to add another conditional formatting clause. I’m sure you can guess how this will look:

1. Right click on your second button and select “Conditional formatting”

2. In the top right task pane, select “Create” and “Hide content”

3. Enter “$Question != $Of”

4. Ok, Ok.

(The above clause says hide the second button if the Question isn’t the last question in the Quiz)

Congratulations – all the hard work is now done! Have a play around in the browser to make sure everything works correctly. You should be able to choose a Quiz, complete all the questions and then be re-directly to the current blank ShowResults.aspx page.

A note about formatting

 

Although (hopefully!) you page works beautifully it’s not currently the best looking web page in the world.

One step you will almost certainly want for your to have your new page inherit the design of your master page. To do this, from the top menu simply go Format | Master Page | Attach Master page

There – looking better already! Save everything (and I would recommend saving a backup of all your pages too) and then play around with making the page look exactly how you would like it.

 

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

Comments

  • Anonymous
    January 01, 2003
    I am having the same problem.  I was even trying to find a way to change the default answer to "Select Answer" or something, that way the user would always have to change the value to something.   Looking forward to an answer, just spent almost two days build this up. Thanks!

  • Anonymous
    January 01, 2003
    Help !!! I did it again from scratch.  Now, when I enter wrong answers, it works: zeroes are in the answers list.  But when I enter good answers, only questions 2 and 3 (out of 4 questions) are filled with "1", questions 1 and 4 never show up. Pleaaaase!!! Thanks

  • Anonymous
    January 01, 2003
    Sounds like URL1 is defined or available.  Can you check you added to the stylesheet?  If you edit the code you should get a XSL helper ... if you type a "$" you will get a list of the available variables - does it show up there?

  • Anonymous
    January 01, 2003
    Nevermind! I found the problem in your instructions. And finally the session ID

  1.       Hit “New Parameter”
  2.       Name=Question  <--- this should say Session
  3.       Source=Query String
  4.       Query string value = Session
  5.       Default value =Session
  • Anonymous
    January 01, 2003
    Thanks NickWu, your suggestion changing the button type worked for me, no more double entries in the answer list. I also went back and added a 'select' option to the AnswerGiven list. This forces the user to change the form and works round the issue of nothing going into the answer list unlesss they do. Works the same as 'nonsparkers' radio button post earlier.

  • Anonymous
    January 01, 2003
    RE: "Thanks for the article on creating a quiz web application using SharePoint designer. I followed the 5 articles and was able to successfully create a quiz application. However, I encountered a challenge: hiding the administrative form fields from the Answers list and leaving only the response field for the user to select the correct answer. I tried using conditional formatting [true()] to hide the controls. This resulted to the field being committed when empty." Well done on getting through all five parts and having a working quiz application!  In answer to you question on hiding feilds. Highlight each field, then in the 'Tag properties' pane (bottom left) find the 'Visible' Attribute and set it to false. EKolle:  Not sure why you can't insert a list form - try removing the web part zone and adding it back in. Regarding the button:  I suspect problems may be due to where you have placed the button.  XSL is very sensitive to scope (i.e. variables are only available in the section they are defined) - a simple table has three or four areas and the variables are only available in the main (Row View) template. Suggest that you move your button into the main form and build it section by section, testing each element to troubleshoot.

  • Anonymous
    January 01, 2003
    Bren, this tutorial is amazing.  I was able to make it to this page before running into an error. Your text: If you like at this point you can save your page and take a look at it in the browser.  You should see the value of the Question parameter in the query string be passing into your form. We now need to do the same with the session and Quiz parameters. Change the format on the input boxes on the SessionID and Exam fields to be TextBox.  Then, for the Text value of session add {$Session} and for the Text value of Exam add {$Quiz}.


When I attempted to input {$Session} in the Text area under "Tag Properties" I got an immediate error. My error: SharePoint Designer cannot render the XSLT in this Data View.  Try to undo your changes or re-insert the Data View. Failed setting processor stylesheet: 0x80004005: A reference to variable or parameter 'Session' cannot be resolved.  The variable or parameter may not be defined, or it may not be in scope.

Again, this is the only error I've run into, so I'm wondering if the {$Session} input is incorrect or possible I forgot something.  Thank you again for this tutorial, and if you read this please contact me asap krevo81@gmail.com

  • Anonymous
    January 01, 2003
    Another update on your guide: In the text below, you identify the change made from one highlighted version to the updated highlighted version which includes "concat" In the guide, the addition of concat to the string isn't highlighted and thus, I left it out of my initial change to the string and received an error.

To do this click on the submit button so that it’s code is highlighted.  Currently it’s associated code will be: <td width="99%" class="ms-toolbar" nowrap=""><IMG src="http://blogs.technet.com/_layouts/images/blank.gif" width="1" height="18"/><input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={ShowQuestion.aspx}')}" /></td> It is the __redirect= section that I have highlighted that we are interested in, we want to insert our string here so that we can pass our parameters. Change the whole string to be as follows (I have highlighted the new section). <td width="99%" class="ms-toolbar" nowrap=""><IMG src="http://blogs.technet.com/_layouts/images/blank.gif" width="1" height="18"/><input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question=',$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}"/></td>

  • Anonymous
    January 01, 2003
    I got my issue to work by recreating the page. I would like to know if there has been any developments on the having to change a value for the values to be entered in to the list. Anyone have any ideas?

  • Anonymous
    January 01, 2003
    Thanks for all your comments ... part four seems to be a sticking point so I am going to run through the chapter again and see if any points can be made clearer (we are doing a lot of things in this section) I've changed the highlighting to reflect your comment. Regarding the answer feild being visible - you can just toggle the visibility of the feild once you are happy with it. I would recommend that you have everything working on the page before changing any of the layout within the Answers section - as moving feilds can make them outside of the scope of the stylesheet and so variables and parameters will not work.

  • Anonymous
    January 01, 2003
    Thanks for this tutorial. It has been great so far. However, I do not have the option to insert custom list form, it is grayed out. I have the Answers zone highlighted but it still doesn't give me the option.

  • Anonymous
    January 01, 2003
    I believe the comment I made above could be the same error that Webweever was receiving.  If you look at the two strings you highlighted, the updated newer string includes "concat" however you didn't highlight it so you'll get an error. Your updated highlighted string should be: concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question=',$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}"/></td> instead of: ;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question=',$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}"/></td>  

  • Anonymous
    January 01, 2003
    Everyone I assure you that you are placing these three lines in the wrong place. I am not a geniouse by any means but i had the same problem until i realized that they had to be in the wrong place because the error states that it specifically cannot resolve or basically find URL3 or URL1. Please go back and place these were they are intended to be. <xsl:variable name="URL1"><xsl:value-of select="$Quiz"></xsl:value-of></xsl:variable> <xsl:variable name="URL2"><xsl:value-of select="$Of"></xsl:value-of></xsl:variable> <xsl:variable name="URL3"><xsl:value-of select="$Session"></xsl:value-of></xsl:variable> Here is what my section looks like: <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal"> <xsl:output method="html" indent="no"/> <xsl:decimal-format NaN=""/> <xsl:param name="dvt_apos">'</xsl:param> <xsl:param name="ListItemId">0</xsl:param> <xsl:param name="ListID">{BCFBF7C6-6726-4D1A-8ABF-A485D3A03A7B}</xsl:param> <xsl:param name="Quiz">Quiz</xsl:param> <xsl:param name="Question">Question</xsl:param> <xsl:param name="Of">Of</xsl:param> <xsl:param name="Session">Session</xsl:param> <xsl:param name="CorrectAnswer" /> <xsl:param name="UserId"></xsl:param> <xsl:param name="UserName" select="substring-after($UserId,'')"></xsl:param> <xsl:variable name="dvt_1_automode">0</xsl:variable> <xsl:variable name="URL1"><xsl:value-of select="$Quiz"></xsl:value-of></xsl:variable> <xsl:variable name="URL2"><xsl:value-of select="$Of"></xsl:value-of></xsl:variable> <xsl:variable name="URL3"><xsl:value-of select="$Session"></xsl:value-of></xsl:variable> <xsl:template match="/">

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    I was able to change the answer given column to radio button and erase set the default value to nothing. This works well for the changing value issue.

  • Anonymous
    January 01, 2003
    also now i get this error This Web Part does not have a valid XSLT stylesheet: Error: End tag 'tr' does not match the start tag 'input this is my code <xsl:call-template name="dvt_1.rowedit"> <xsl:with-param name="Pos" select="concat('_', position())" /> </xsl:call-template> <tr> <td class="ms-toolbar" nowrap=""> <table> <tr> <td width="99%" class="ms-toolbar" nowrap=""><IMG SRC="/_layouts/images/blank.gif" width="1" height="18"/><br /><input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question=',$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}" > <td class="ms-toolbar" nowrap=""> </td> <td class="ms-separator"> </td> <td class="ms-toolbar" nowrap="" align="right"> </td> </tr> </table> </td> </tr> </xsl:template> thanks again

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Got it working, after deleting and re-creating the questions and answers lists.   Now, does somebody knows how to modify the application in order to avoid that a user answers a question more than once (e.g. by using the back button and submitting the answer again)? Thanks!

  • Anonymous
    January 01, 2003
    Hi, Thank you for the great post. So far I am able to implement your solution without a hitch. I just want to comment though as this might be useful to others. This refers to the sub topic "Loading a system variable (current user name) into a custom form". I changed(i.e. UserId into UserID as SPD 2007 has UserID in the parameterBinding section of the code). Basically changed this code: <xsl:param name="UserId"></xsl:param> <xsl:param name="UserName" select="substring-after($UserId,'')"></xsl:param> into this: <xsl:param name="UserID"></xsl:param> <xsl:param name="UserName" select="substring-after($UserID,'')"></xsl:param> Thanks

  • Anonymous
    January 01, 2003
    Oh and the US Navy Thanks you for saving us 500 bucks!!

  • Anonymous
    January 01, 2003
    Bren, Everything was working just as you wrote it for me until the Button. I'm still stuck there.

  • Anonymous
    January 01, 2003
    I am having the same problem, but it doesn't matter whether the webparts are connected or not, what seems to be the issue is, I HAVE to CHANGE any value on the form for it to create the list item. Editing a value and putting it back to the "default" doesn't work either. For example, if the form loads with "Correct Answer" field with an "A" in it, and I change it to "C" and submit it will create an item, but if I change it to "C" and then change it back to "A" no dice. Also, if I change the "title" or any other field, it also works, so somehow its refusing to "commit" unless some value has changed????? I'm hoping this will help someone figure out what is broken here, I'd like to use this technique in another more complicated web-app.

  • Anonymous
    January 01, 2003
    I'm trying to change my button link to read redirect={ShowResults.aspx?Title=',$URL1,'&amp;Session=',$URL3,'}'))}"  /> like yours above and I'm getting an error. I have the syntax correct, the error I get is: Failed setting processor stylesheet: 0x80004005: A reference to variable or parameter 'URL1' cannot be resolved. The variable or parameter may not be defined, or it may not be in scope. Does it matter where in the form I place the submit button?

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    Great tutorial! I'm done with part 4 and when I click the submit button, only the "good" answers are inserted into the "answers" list.  From the list itself, if I type in a wrong answer, the calculated field does its job: a 0 is inserted.   So I suspect something is wrong with the transfer of parameters between the questions and the answers webparts but I can't figure what it is. Another thing: still on part 4, you mention the "IsCorrect" field.  Would this be the "MarkAnswer" instead?  Can't find it anywhere. Thanks again!

  • Anonymous
    January 01, 2003
    First off this tutorial is awesome, thank you. The only problems I am running into, aside from allowing blank answers, are the UserName and hiding the fields.  I have everything entered as above and all the other fields populate when I run the quiz, but the UserName does not populate the Title field.  There aren't any errors at all, it just remains blank.  If it helps we are running Sharepoint Services 3.0...I don't know if the parameter changed from UserID or what.  Any ideas? As far as hiding the fields, I know how to do that, but the labels next to them...can I just delete those safely? Thanx again for the effort put into this...it really is amazing!

  • Anonymous
    January 01, 2003
    Hi - thanks so much for the feedback and the correction.  I've changed the post to reflect the error you picked up on (its seems its all too easy for little errors to creep into long posts like this but I know how frustrating it can be!).  Thanks again.   Bren

  • Anonymous
    January 01, 2003
    I was getting duplicate items in the answer list when hitting the submit button. I changed the type attribute of the button from "Submit" to "Button" and it seems to work fine now.

  • Anonymous
    January 01, 2003
    Hi - I know the problem you mean.  I'm afraid I haven't got a ready answer to this one.  I will play around when I get a little time .... if anyone has cracked this already please share!

  • Anonymous
    January 01, 2003
    Has any one had any issues with the Session variable and  Quiz variable having output escape characters in the submit button code? I'm kinda new with SharePoint Designer and xsl. I can't figure out how to get it to stop. It doesn't happen with the hyperlink on the default.aspx and when I just output the variable the  escape characters are not there. Only with the submit button code does it replace the : and spaces with the escape characters.

  • Anonymous
    January 01, 2003
    Hi Bren, Thanks for a great tutorial - the detail makes it easy to follow!  Everything has worked fine except I have noticed two weird issues when implementing this part of the process.   (1) I find that when I submit an answer, I don't get a row created in the Answers table until the user changes the answer from the default (eg if the default answer is 'A', I only get rows in the table when the user selects answer 'B', 'C' or 'D') (2) If I try to work around this by forcing the user to select an answer (by making the default value of AnswerGiven empty in the list's settings), then no validation kicks in on the page, so the user can happily submit a blank answer. What's strange is that this only happens once the Web Part Connection is in place between the Question and Answer Data views.  If I temporarily remove the connection, then (1) even if I don't change the answer from the default, a row still gets inserted and (2) if I default AnswerGiven to blank, the validation correctly displays 'You must specify a value for this required field'.  Of course, with the connection removed, the CorrectAnswer no longer gets filled in. I have rebuilt ShowQuestion.aspx twice now from scratch and have had exactly the same issues both times; I can reproduce the issue trivially by alternating between deleting and creating the web part connection. Any ideas?

  • Anonymous
    January 01, 2003
    Not sure what you're asking me to do however the contents of my ShowQuestion.aspx file are at the link below. http://www.racinnation.com/ShowQuestion.txt Thanks for your help.

  • Anonymous
    January 01, 2003
    I agree with everyone that this is a great tutorial. when i submit the answer it is added twice to the answer list. any ideas?

  • Anonymous
    January 01, 2003
    post above link should read: ;__redirect={ShowQuestion.aspx?Title=',$URL1,'&amp;Question=' ,$NextQNumber,'&amp;Of=',$URL2,'&amp;Session=',$URL3,'}'))}"/> That's the one I'm getting the error on. Sorry

  • Anonymous
    January 01, 2003
    Really useful tutorial. I too have the issue of nothing going into the answers list unless a changed is made on the form. After selecting a non default anwser I also get two identical lines added to the answers list. Anyone solved these issues?

  • Anonymous
    July 28, 2010
    How do we hide the all the fields except for AnswerGiven in the Answers?

  • Anonymous
    July 29, 2010
    Oh so close.  I made it to the submit button and found that my quiz name,  "Tyler's Test Quiz" was breaking the javascript due to the apostrophe.  Perhaps the title should be escaped somehow?  It's tricky when you look at the click hander.... "BLOCKED SCRIPT__doPostBack('ctl00$m$g_37582263_8461_45e5_8c0b_97175d382ae6','__commit;__redirect={ShowQuestion.aspx?Title=Tyler's Test Quiz&Question=2&Of=5&Session=2010-07-29T20:36:04ZTSWATERS}')" The apostrophe ends the second parameter of the __doPostBack function.  Could probably get by with an XSLT Search & Replace function... replace ' with '

  • Anonymous
    October 28, 2010
    Hi, I got a problem here. When the answer is submitted, a new answer list item should be created. However, I didn't found any new item created under Answer List. It able to redirect me to next question, all value of query string and server variable able to show on Answer List form on this page.  Below my code on ShowQuestion.aspx Form action for submit1 button: <xsl:if test="not($Question = $Of)"><input name="Submit1" type="submit" value="submit1" onclick="BLOCKED SCRIPT {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&Question=' ,$NextQNumber,'&Of=',$URL2,'&Session=',$URL3,'}'))}" /></xsl:if> Form action for submit2 button: <xsl:if test="not($Question != $Of)"><input name="Submit2" type="submit" value="submit2" onclick="BLOCKED SCRIPT {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowResults.aspx?Title=' ,$URL1,'&Session=',$URL3,'}'))}" /></xsl:if> Could you advice? Thanks.

  • Anonymous
    October 28, 2010
    Any updated change on the 2nd button? The highlighted changes above give me the error below Failed setting processor stylesheet: 0x80004005 : Expected token '}' found ')'. BLOCKED SCRIPT {ddwrt:GenFireServerEvent('__commit;__redirect={ShowResults.aspx?Title=',$URL1,'&Session=',$URL3,'}')-->)<--} can someone help?

  • Anonymous
    October 28, 2010
    Thank You for this very nice tutorial, I think there is  a typo, It shoud have mentioned <xsl:param name="UserID"></xsl:param> instead of <xsl:param name="UserId"></xsl:param>

  • Anonymous
    November 02, 2010
    Quote emcs2 Hi Bren, Thanks for a great tutorial - the detail makes it easy to follow!  Everything has worked fine except I have noticed two weird issues when implementing this part of the process.   (1) I find that when I submit an answer, I don't get a row created in the Answers table until the user changes the answer from the default (eg if the default answer is 'A', I only get rows in the table when the user selects answer 'B', 'C' or 'D') (2) If I try to work around this by forcing the user to select an answer (by making the default value of AnswerGiven empty in the list's settings), then no validation kicks in on the page, so the user can happily submit a blank answer. What's strange is that this only happens once the Web Part Connection is in place between the Question and Answer Data views.  If I temporarily remove the connection, then (1) even if I don't change the answer from the default, a row still gets inserted and (2) if I default AnswerGiven to blank, the validation correctly displays 'You must specify a value for this required field'.  Of course, with the connection removed, the CorrectAnswer no longer gets filled in. I have rebuilt ShowQuestion.aspx twice now from scratch and have had exactly the same issues both times; I can reproduce the issue trivially by alternating between deleting and creating the web part connection. Any ideas? Anyone found out whats the problem, otherwise the quiz is just great.

  • Anonymous
    January 13, 2011
    The comment has been removed

  • Anonymous
    January 19, 2011
    Ok, great demo, thanks for putting it together. I wanted to summarize some of the problems/solutions which have been raised/ I have experienced. #1. The UserName being blank.  The code listed here cuts the string where the "/" is.  Therefore, if your company has SP set up for a userID like LASTNAME, FIRSTNAME it hoses the code.  Therefore I changed my code to look for the comma and give me just the last name. #2. The Session string created.  Same thing.  I changed it to just get the LASTNAME portion of the userID, but also the session is returning as: LASTNAME2011-01-19T17:54:58Z and the colons seem to be hosing the "Submit" button.  I haven't figured out how to replace them with something else yet. #3. Several people (myself included) were getting a "A reference to variable or parameter '____' cannot be resolved" I found that for me I had added the parameters to the TOP web part rather than the bottom one.  Moving them down resolved the issue.

  • Anonymous
    February 23, 2011
    Hi very nice post i done it as it is mentioned in the site , in the final step the Result.aspx after copy paste the XSLT code i got the same look and feel as it is in the site but after attending quiz it is not show the pecentage and the percentage with bar after hitting the button for the final answer

  • Anonymous
    February 23, 2011
    Hello my issue is i want to display the result of the quiz that is Username,type if the quiz,passmark  and  with Grade 'Pass' or 'Fail'  in a seperate custom SharePoint List how is it possible  can you please anyone help me out!!!

  • Anonymous
    March 07, 2011
    Great tutorial.  I have a different issue.  When I attempt to reformat the contents; change the display of "AnswerA" to "A" on the ShowQuestion.aspx page which is just text it breaks the insertion of the answers list.

  • Anonymous
    April 12, 2011
    Thanks for the wonderful aritical. I have created the Quiz Application successfully. :)

  • Anonymous
    April 12, 2011
    The comment has been removed

  • Anonymous
    April 13, 2011
    For those that are unable to get the Title field to populate the UserName, this is what's wrong (Remember that the xsl codes are case sensative, thanks Brendan Clarke for teaching us this): Search in your code for the following: <xsl:param name="UserId"></xsl:param> <xsl:param name="UserName" select="substring-after($UserId,'')"></xsl:param> Note that UserId needs to actually be the following: UserID Perform the change in those two lines and your title field will populate with the UserName. Brendan Clarke, thank you so much for this article. Now if I can hide the fields I don't need to be shown in my quiz, I will be finished.

  • Anonymous
    April 14, 2011
    For those that are having a problem with the first submit button, more than likely it is a problem with where you are placing the following code: <xsl:variable name ="NextQNumber" select="$Question +1"></xsl:variable> It must be placed at the end of all the <xsl:template> codes of the second web part zone. This is what my code looks like so you can have an idea where it should be placed: </xsl:template> <xsl:variable name ="NextQNumber" select="$Question +1"></xsl:variable> </xsl:stylesheet> </Xsl> </WebPartPages:DataFormWebPart>

  • Anonymous
    April 14, 2011
    "(1) I find that when I submit an answer, I don't get a row created in the Answers table until the user changes the answer from the default (eg if the default answer is 'A', I only get rows in the table when the user selects answer 'B', 'C' or 'D')" To resolve this issue, what I did was go into the Answers list using the web interface, select settings, list settings, click on "AnswerGiven," and changed it from a drop-down menu to radio buttons while also leaving the "Choice" field blank. "(2) If I try to work around this by forcing the user to select an answer (by making the default value of AnswerGiven empty in the list's settings), then no validation kicks in on the page, so the user can happily submit a blank answer." It should be possible to use javascript to not allow the user to proceed to the "next page" unless an option is selected... I'm not sure what the coding for this would be or where in our code it should be placed...

  • Anonymous
    May 16, 2011
    I've had no problems until I hit the submit button. It seems that all it is doing is refreshing the page. How can I fix this? I've clicked 'View Source' when I pull the page up, and it does increment the question. I've also gone to the last question of my test (by manually entering the question number), and the second submit button does the same. But on a test where there is only 1 question, the second button works fine. Any helped would be most appreciative.

  • Anonymous
    May 17, 2011
    Workaround to my problem: I added a QuizID column that links to the ID of the Quiz list. Every list has it's own ID field, so a unique name is required. Now I am encountering the problem listed above, with the blank selection being allowed.

  • Anonymous
    January 10, 2012
    Not sure if this Thread is still active but I have a question if anyone is out there. First of all this is a awesome tutorial and I have got everything working great so far except the last step. The second Submit button works perfect until I use the code to populate the Session and Title on the Results Page. Once I put that code behind the second Submit button it no longer takes me to the Results page. I remove the code and use the original code and it works fine. Any suggestions? Thanks

  • Anonymous
    January 13, 2012
    One issue I came across was with the Submit button not loading the next question. In this post you instruct to create a page called ShowQuestions.aspx but later on your instructions for the submit button is linked to ShowQuestion.aspx Change the whole string to be as follows (I have highlighted the new section). input name="Submit1" type="submit" value="submit" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={ShowQuestion.aspx?Title=',$URL1,'&Question=' ,$NextQNumber,'&Of=',$URL2,'&Session=',$URL3,'}'))}"/> Basically it just needs to be pluralized.

  • Anonymous
    January 26, 2012
    I'm sure this is a so nice example of dataview usage and custom solutions without .Net development. I just have a consideration about it: I'm having the same issue of duplicated entries on Answer list. But this problem just occurs when I'm using Internet Explorer (7,8 and 9). On Mozilla Firefox, Google Chrome and Opera it doesn't occurs. Could it be a wrong javascript interpretation on submit input? Tks!

  • Anonymous
    July 18, 2012
    The comment has been removed

  • Anonymous
    May 29, 2013
    The comment has been removed

  • Anonymous
    June 05, 2013
    The comment has been removed

  • Anonymous
    June 08, 2013
    In answers list   If corect answers=given aswer..Mark answer still shows 0 .Can anyone help me out in this? tHANKS IN ADVANCE

  • Anonymous
    July 03, 2013
    Could you chk your formula again. It shud be - =IF(AnswerGiven=CorrectAnswer,1,0) This works for me, did not find any issue..

  • Anonymous
    July 04, 2013
    is it possible to display random questions?, if so hw can it be done? Thanks in advance

  • Anonymous
    July 08, 2013
    First of all you need to add sharepoint form action button. once done you ave to right click the button-->form actions-->and then from the action list add COMMIT click ok.. Hope this would be of help  

  • Anonymous
    September 09, 2013
    For those having a problem with the SECOND SUBMIT button, the highlighed area in the original text is incorrect.  Basically, you need to change EVERYTHING inside the GenFireServerEvent.  Change to the following (Leave the original open paren): concat('__commit;__redirect={ShowResults.aspx?Title=',$URL1,'&Session=',$URL3,'}'))}"  /> And you should not get any errors. John

  • Anonymous
    March 26, 2014
    Did someone face any issues incrementing the variable in Sharepoint 2010?
    I can not make it work. I think my issue is in the scope of the variable NextQNumber can someone that has the quiz working on sharepoint 2010 help me on this if possible please send me the ASPX code to compare the code and find out what is the issue.

  • Anonymous
    March 04, 2015
    Hi Jose

    I think that is my problem too, the answer submits to the answer list but will not change to the next question. Did you or anyone else have a fix to this issue? I am also using SharePoint 2010

  • Anonymous
    June 24, 2015
    The comment has been removed

  • Anonymous
    September 27, 2015
    Hey guys, solved the problem of the answers not calculating correctly i.e. the result still gets 0% even though the answer is correct etc etc.
    During the set up of the 'Answers' web part in part 4 of this tutorial, you will find that the 'MarkAnswer' field does not appear after inserting the custom list form. All you need to do is just include it underneath the 'Session ID' codes.

    E.g code for the 'MarkAnswer' field:


    MarkAnswer:












    Just paste that right after the code of the 'Session ID' field.

    Yes. It breaks the connection if the codes are not there. Some of you may have realized that after you deleted off the non-required fields to hide them. I did that too but I suppose that's not the 'right' way. What I did to hide them was 'visibility:hidden' in the style of code in each of the fields. E.g.


    SessionID etc.. etc..
    I'm not that code savvy and I know it's not the best but at least it's not there.

    Hope this helps you guys although I think it's probably way too late... haha!
    ^_^;