Thursday, May 29, 2008

Video: Building a Quiz Engine 4

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will complete the Quiz Engine project, adding theme support, cleaning up the code, and deploying the project.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

In this video will finish up our ASP net two quiz engine project to start with snapshot six for and themes and skins for project and snapshot seven will refine this functionality so that our users can select their preferred theme for our site and have their preferences saved for future visits and finally inception Rehberg will try look at some of the spots that are code and we can employ some better exception handling organ added error page for our side and then we ll speak briefly about deploying the site to a Web server so in snapshot number six I wanted to add the ability for users to select their preferred skin another was the graphics in the textiles they give our site its distinct visual presentation quality in all honestly was a little gratuitous and need for this type above website and we really need this sort of functionality will probably not nonetheless it s a nice touch and we didn t talk about the
Minute 1

In our discussion of ASP net to go so I thought it would be muscle addition to what would working on that s probably a feature that is best used on applications and websites that are very personalized double like a portal for sample inception of six will look at some of the first steps I took and I brought this up in two steps the first step is just getting the themes set up and working on the pages and in the second step would be to allow the user to select which themes they want an essay that into their profile information and assorted discussant snapshot seven in just a moment now there s a number of ways to employ themes and skins in ASP net to go Alexa me other things about ASP net there s a lot of options here in America ticket I m discussed all the permutations about this on working on the Sears video zone where Visual Studio net that will go a lot of depth on this particular topic and shouldn t be a lot of good articles on MSDN throughout the net community
Minute 2

But at a high level there is a difference between a theme and his skin and as the net vernacular a theme works at the page level in his skin works at the control level a theme can define multiple skins each control can determine which skin that is going to use for simple you might define to skins for all ASP net button server controls you may have two different usages for buttons in our case think we have a wizard style navigation in our questions page for example and then we have those just general submit form functionality buttons that use the button control or we may want these to look different visually in which case we would assign each of them a different skin ID that is defined
Minute 3

In eight skin file however the skins are somewhat related they may all have a certain border of text or font properties of caller that fits into a certain theme that we might have a whole other theme that has those same skin IDs defined but with different borders fonts and color schemes so once again there s a lot of flexibility here and it we can t spend enough time really diving into this beyond the particular implementation so was talk about article notation in our case much of the stylistic aspect of our application is defined in the styles CSS file and then also we have images folder that has a little banner images at the top of each page so what I would do is show how to use themes to change out the style sheet and those graphics identity to mind
Minute 4

At a lot of flexibility animal and demonstrating one way to employ themes and skins within your app so one of the first things I did was create a new app themes folder is as simple as right clicking on my project and selecting add folder and you can see that theme folder is one of the options here within our project when I selected that it created themes folder for me next I need to create individual themes within my theme folder so again it s as easy as a sole right clicking selecting add folder and then clicking theme folder from the context menu on site maintenance of my theme folders these become the names of my themes each theme folder contains out resources for that particular theme for simply can see here that I have a sober esque AIN file and I can define multiple skin files within my theme
Minute 5

Each skin file can define how one or more server controls should be rendered so what changes there should be individual property of that particular skin and you can define multiple skins for a given server control but each skin has to have a unique skin ID for that particular server control so too have the same skin ID for a button and a label that s okay but you can have to skin IDs were to what and definitions that would make and he says that a flip middle distance art also can see here that I have my stylesheet source basically moved my stylesheet from the the same area that was in the root of my application to this new a sober directory and I also have my images folder contained here as well
Minute 6

You see that I don t associate the exact same thing with another theme that I m calling red I have a Redskin which were to look at our skin files in just a moment and images folder with unique red images that will be used in place of the silver ones and then a new style sheet that will define visual properties for my for my Redskin for the text for of the any borders in the font database of that nature okay so one of the things that I needed to do and I do miss him in a particular order actually I kind of it was an iterative process fluoride to little bit of work in in for example my default page and then worked on my skin file open until I got everything working the way I wanted to but let s start by looking at our default aspx page in consumer the first things I did was that
Minute 7

I changed out the image tags as the regular HTML IMG tags and change them out for image server controls so you can see here that I for example that a welcome border I changed out from an IMG SRC images welcome gif I changed that to ASP image I d made the IDC image welcome that s not as important as the skin ID which I called welcome ballistic look and are so versed skin file and see how that s the fun you can see here is there some example text that skin for use in examples that you can not draw from this help me out what it is always working on this you see this first image control that I define our greatest skin ID called welcome and in it
Minute 8

To find the image URL I couldn t find any of the properties of a image control that has this particular scan in this case the only thing I really change is the image URL to the silver folder images welcome gif melon theory I think of this I don t need to add that but this is the way that I got it to work so I was I left it in there but you may want to experiment with the whether or not you need these world pets okay but at any rate you can see that I ve defined skin IDs for welcome line main menu twist with starting a recover password and results each of them point to different image URL snuggling back to our default aspx page was continue to look for other image controls that were added
Minute 9

Conceded that I have an image lying so it s an idea of line in salon and there are some others here looks years another longtime image line to skin ID of line and database here is a main menu so within our login template we changed our welcome to to main menu of a header graphic and in this case we have a skin ID for main menu to support to the main menu gif file to see my sale till this doesn t make a whole a sense why did you make things essentially a little but more complex well we added a level of indirection within our application so that it gives us added flexibility now all we need to do is tell our page which seem we want to use and as long as both teams have a definition for skin ID of line of skin ID of a
Minute 10

Main menu lists get ID of a welcome now I easily given to looks to visual quality presentations to the exact same page so where do I define lights a theme that this page useful that is a good question and there s many different ways to do that just for testing purposes in this first half shot wide did was hardcode that essentially and the page directive so can look at the very top whatever page directive where we define what our languages in and know the code file for application so on and notice here that I have a theme equals will read so by default will be using the red themeless runner application
Minute 11

In why is that in wise the login redwood before it blew only changed the the CSS file the styles of CSS or change the the the color property for the text also noticed that the banner graphics are different the line is different functionalities exactly the same now how can I change back to the silver theme easy to just change this to silver fingers on the colder I must delete all this is a dizzying Tolleson sticking in theme equals in the notice that gives us two options redder sober so visual Web developer can basically deduce which themes are available and provide those to you in IntelliSense yarns for selected and hit the my keyboard and notice that it fills it in ending very cool Tony a petition again having made
Minute 12

That single change and notice now we re back to our previous color for text defined in the styles of CSS we have our original welcome graphic because that s over ice blue color and then also lower gray line graphic okay so this is all well and good however we don t want to defined things in this regard we want our users to be able to find a solo works each user should be able to determine how they want to see our webpages of do they want the red themeless over theme oriented themes that we have available for them and so now having finished up a snapshot number six when you consider how organ accomplish this for snapshot of number seven
Minute 13

So it s now shot number seven in this national really do is enable the user to select which theme they would prefer to look at as they login to our website and interact with it so Lessig look at our default aspx page and want to struggle to look for small to design view and talk about where the selection can be made make sure you for following along that you select the long view and you choose the login template because the user will need to be logged in in order to persist their selection this will not work for users that are not saved within our own personalization membership of the database in our app data folder the AFP that DD data via again just to refresh your memory we did to Mabel that
Minute 14

For ASP net configuration selection on on her menu and from our admin tool of the security tab and the same functionality that enables us to defined users and allow or deny access based on the acts whether or not that they have an account with us is the same full generality that allows us to persist other property is that are called the profile sortable saves information about a user in their profile object and will topple that more just a moment what would you scroll the very bottom us to learn verb on your knees him a very simple implementation of the theme preference selection first law have basically two hyperlinks so for red October and ostrich are in the sober of notice that I am looking at a simple on anchor tag
Minute 15

At the HREF is default aspx and then I have a query string theme equals in this case over for a select for red hyperlink the anchor tag and go down to my HREF property notice that it s exactly the same the only change is your change is that the theme equals read in this particular case so I m this will refresh this page and send back a query string of the selection of the user know the real trick is in the code that will interpret this of this query string and then decide what to do and usually three tasks that are protest accomplished the first one is to retrieve the value of our query string based on that changed the theme for this page and then also we need to persist that selection for two reasons persisted so that each page from this point on our questions to
Minute 16

Itch to start page the results pages so one so that they will use the same theme that was one of user and also if the user will want out come back a week from now we don t want to have to reselect their preferred theme we want to store store that for them and really personalize their experience a closer look at the code for our fault that his deputy A file are so here we are noticed first of all it is that I am setting the page theme property themed property for this page 2 the value this currently stored in the profile theme object or I so where do we define this property the theme property remember that from our previous discussions about the profile object that we define this little cash of
Minute 17

Properties for all of our users that is safe in our ASP net TV MDF file in our web config soul is open at up and take a look at the system Web element of our web config file Mr we have a profile section profile property enabled set to true and then we have the ability to add a list of properties in this case we have only one property we ve added one called main I m sorry we ve added one called theme we can add as many as we want here in store information is pertinent to a specific user or so every user will have a property called team stored in their property cached EPA s peanut DB MDF file for that user that is where we defined everything now notice your root of this line and select profile and notice that
Minute 18

I get IntelliSense that allows me to see that it strongly typed that is recognized by ASP net and buy in particular gets visual Web developer 2005 express edition and it s a valid property for me to use so I get that had a benefit which is very cool now was back on hold it and talk about how this gets set for small notice in 121 or working with the page_Paris initialization rather the Paris in the event if you tried to set the theme property for our page anywhere but in the Paris initialization event you will give you a build error that says essentially you can only set the theme property in the initialization event so we have some page Korean vets Center each is an arts handles
Minute 19

He taught Paris and in Visual Basic next notice that the first thing I need to do is check to see if there s a query string called theme if that is not an all and then we want to retrieve the value and place it in our profile name property once we have that now we get to check to see if the user is currently logged in the waiver to do that is to see if this user is anonymous if he is anonymous then there s nothing we can do for them we can not change the page theme because we can t use the profile object because the user is currently anonymous so we ll skip everything after line 27 and basically seven to a default theme for our page however assuming that they are logged in
Minute 20

And assuming that they have something stored in their theme property for the profile object and will take that value and set it to our page and is prevented to the vote will accommodate our request that so what happens if first of all a particular user does not login or what happens to in this case the default page before they get chance to log in well that s handled back our fault aspx page to the source and recall that we set the theme property of our page directive to silver this will be the default theme that s employed okay so that s writes everything seems to look good for our default page was to look now at those pages that will be affected by this
Minute 21

And those pages would be a start page the questions page and the results page but not recover password Why not will because you don t have to be logged in and order recover past passports were not worry what that page over the star the questions and the result is willing to do first of all is creates the kind of a smaller version and easier dumbed down version of this page of a screen that event and simply check to make sure that the user is logged in but they ve set something for their theme if they have within the profile object are going to take that value and set it to our page sucking property to novel again what happens if they don t have something saved in their profile got been property off going back to our
Minute 22

Ellis run application will stop here for a whimpering at the start page first book and so it didn t pop us to default is great or excellent login remember that were logging in as admin so a DMI in password is OPA SS death of Yorty one plug in is on notice that I ve were to run this application obviously as I was developing it and for this the single user he said his preference to the red team on a change that to the silver themes would go to the next page based on a shutdown or browser on the start of the application again and I m going to login a second time admin has looks at were one okay so I m logged in as admin again now looking at the silver theme I would change back to the red schemes go to the available to
Minute 23

Best great sugar down runner in this time let s make sure that we have indeed cool respecting here hands you can see indeed it is saving our theme preference for this particular user recall that so that pretty much finishes up a very easy implementation for our purposes and now we want to focus on those final steps in snapshot number eight in the final steps that will include adding some exception handling adding an error page in and talking briefly about how to deploy this day sorting Lucas Nash a memory in the snapshot were going to clean up some rough edges to look for testing and look for opportunities where we can improve
Minute 24

And of exception handling and it also makes and provisions for when bad things happen to good applications led and an error aspx pages will top alleged moment okay so distorted bass celebs looking for places where you clean things up on notice that I moved line 19 of those form of formerly line number 17 to only execute under certain conditions approaches pages being posted back and if the profile if the user has essentially logged and then we will honor at a session of the cult username so the small improvement on the start page added some additional try catch statements with some sorry on the questions page and some try catch great okay so essentially I identified to potential problems on the questions of its pics of VB file and that is a
Minute 25

Of where working with databases things can go wrong whenever working with things are stored in memory things go wrong of present what if the users of session times out what if the server is reset while they re taking their quiz what if the database somehow becomes corrupt goes off line of our just generally becomes unavailable will those are things that we need to account for their application so I decided to wrap those within attractive statements now the challenge is always determining what you should do whenever things go wrong and as I ve noted here you can read my little diatribe about my thoughts on this particular the titular thing but it really pays to be empathetic with the user take a break at work in the computer think about what needs to be users as application and to be halfway through your quiz and something goes wrong what would you want to see well for
Minute 26

All you will want this to happen but what if it did won t you want to occur well in some ways were the medieval comedy those request basically because this is just a tutorial on the sure I d make this completely 100 foolhardy or or impervious to any problems that ever occur Bristol Road not to think through those things in my case I did knew very weaselly cheesy way out and that is to simply send them back to the default aspx page other options I could try to send myself an e mail to webmaster from the spot right here in our catch statement I could try logging this exception to be to the log file on I could rolled the exception after that so that the user will then be sent to the air aspx page is wrong but while options are in this particular case I didn t do that but that s something that we may need to consider and future erasures over application of essentially gets down to the
Minute 27

Issue of how much time you have and howl of many times we have run into these situations and based on that and you have to make some decisions about where you re going to do similarly render the same kind of considerations on the results page so here s a scenario I ve almost finished with my quiz I go to the results page were supposed to store the results of my quiz and present them to me and between the last question of the quiz and the results server is reset the database goes off line whatever the case would be number to for potential problems what happens then well very similar in thoughts of him as you see here and I ve actually continue to live theory here it reminds me of a great programmer quote I once heard 9 10 of 9 10 of a program is handling exceptions not the rule and its so many times I feel like we spent a lot of time
Minute 28

Olds but not protecting the user from the bad things that can happen unfortunately I m practicing better by merely setting the user back to the fall page when I could in fact be doing similar things I ll leave those to you and to future potential or rations of our application bone bad things do happen with our application we want to give the user some feedback so I created a very simple error aspx page I set the default theme and the and basically just said don t panic you did nothing wrong how are we to run a small problem on our side that may have affected the data you re working with on the website what Paul does was assured that our programmers will be flogged and tortured for this and said what I did was go to our trusty is net configuration tool go to the application tab and
Minute 29

That the default error page for application selecting or error aspx page and clicking save the and now if there are exceptions are thrown bar pages then it leads the user will be presented with some information that it wasn t something they did that is something that ultimately were responsible for so fat free lunch tables that have shown a now worthy and all we need to do is deploy our application and as we the demonstrated approves video does become super easy again you have to make sure that your hosting company or the servers that you re deploying this application to have the net runtime to the auto installs
Minute 30

Of selecting our project clicking the copy website button which brings up our copy Web tab setting our connection and again we demonstrated how to do this in a previous video by clicking the connection but we get to define the server properties weather were deploying on our local area network of more to an FTP sites or to remove side using FrontPage extensions to but at a rate no matter what we select we select our files and select go transfer and our application should work again deployment is an absolute breeze in ASP net two auto okay so we come to the end of this 14 lesson series are spent several hours listening to me talking to God this point so first of all I want to say congratulations that is a feat in an
Minute 31

Self and his most much appreciated I hope that you of as a result of these lessons get a better appreciation for the depth and breadth of ASP Napa net two auto that inspired you to take the first steps to develop your own applications and to just experiment to play around and I wish you great success in doing this we can be of any benefit to you learnVisualStudio net please visit us and consider subscribing so thank you and good luck

Video: Building a Quiz Engine 3 C#

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will continue the work on the Quiz Engine, adding the ability to save test results and other functionality. This will allow you to exercise the skills developed in the earlier videos.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

This video to your discussion oh the ASP net 2 0 quiz engine that we ve been working on one single look at snapshot number four and we had two basic goals for the snapshot the first goal was to tackle the saving of the test results into the database so to set up a scenario again the usual come in selected tasks to take to wind up on the questions aspx page or recall from there the bookkeeping the next button effort to make the selection for the correct answer and as a gift to the end of the questions Bill Clinton as results aspx page which will display each of their selections and weather was correct or incorrect by selecting the little link to the left hand side will be able to then view to the particulars for that given question posted a question text all the possible answers and in which the
Minute 1

The correct answer and finally a textual explanation as to why that particular answer was a right or wrong about this one time only been displaying the results we haven t saved the results back into our quiz i database so that s one of the things that we needed to for this snapshot and after we said the results to the database will need to display them you recall from our discussion in the previous two videos were going to test the display those here in on the default aspx page under test results history so will display what the quiz name was whether when it was completed to date and time of the correct answer count and a number of questions and ideally we would want to display the percentage corrected softener mockup however we ll talk with us in just a moment Iran is in problems in terms of
Minute 2

How did you get that information displayed out let s step back and look at our results aspx page particularly the code that will save our test results into our database single look at the results aspx CS file ends at the fuels take a look at our page load were to make sure first of all to only review the code from 121 to approximately 35 where were checking to make sure that were not posting back so this is should only run the very first time that the page is displayed to the user in case not any subsequent times the user may click on the little links next to individual questions that so basically here will want to do is create a new SQL data source as a look at this is an example of creating a data source purely through code at this point we ll then dragging and dropping the data source either from a toolbox or
Minute 3

Going to our own art data menu item to create a new SQL data source in this case with his accrued from scratch Remus set the connection string and the insert command and then set the insert parameters are using the insert parameters add method to insert up first of all the name of the parameter the value of the parameter and if each one and notice that these parameters these four primers we ve listed are contained in our insert command through the simple use of an ad symbol before the name of the parameter that we want to identify and so the quiz ID daytime complete correct answer counting username all correspond to these input parameters that we have specified here within the value section of our insert SQL commands and then we simply call
Minute 4

The insert command of our SQL data store s now unfortunately I chose a bad name will correct this in the next snapshot I just want to see this work and I kind of got stuck in using it will remain will respect for it so that it is a given a more appropriate name however after testing this it was very simple to use this this SQL data source to set insert command set the parameters and then insert the record in the database improves versions of video net it would not have been quite as simple so this is a welcome improvement to the other data access model so now that we successfully save the data in the database were going to need to display the results to the user back on our default aspx page of the first low stock started to talk the page you can see here that I had
Minute 5

Data bound the available tests I set the SQL data source to basically just full all of the does the title from the quiz because now the first challenge that IE came to was that I realized I might want to display some additional information about each of us has that I wanted to make available so right now I simply have a title but perhaps many more information for example a description on so this really forced me to first of all reconsider my quiz tables designed so we may need to come back to that but as a first pass I was able these bind the title to a listing hearing will notice that I also need to then Chris insert a hyperlink that when you click it will send the user to the start page so we haven t done that yet and the reason we haven t done that because I ran the little bit of a problem that caused me to rethink a lot of things
Minute 6

Grid on the default aspx page the test results history my biggest challenge in this snapshot was performing the calculation of the percentage correct in the test results history as once you have the final two columns correct answer count the number of questions displayed for performing a third calculation world actually get a percentage grew to be a little bit challenging now if I m only storing the total number of correct answers I have to pare that up with the total number of questions on a given test an estimate of probably require pretty hairy query on my part and I went down that path also what came up with but I think it can be a eye thing to be done and but then I still had to figure out a way to perform the percentage calculation you in the SQL query or the control itself after spinning off 15 minutes 30 minutes looking at it and thinking of solutions for ads decided that made any disgruntled that an brief think
Minute 7

The user quiz tables design with a look at the data source for sure the direction I was heading down before I came to this conclusion Solana click configure data source were going to then here take a look at the select statement I actually use according older to help design is however you can see it so convoluted this point accord builder can help me out essentially what wanted to do was attempt to join the user quiz table to the quiz table on the quiz ID field for that s what this one the sequel does many as you can see I tried to on to account of the number of questions for a given quiz and in all the rest of the information from user quiz like the daytime complete the correct answer count of this title and so on and then needed to group buying is a having statement as well and so this was again fairly complex is
Minute 8

A lot of time and in one of schema wills it never quite the me the results that I really needed as a vested tip whenever you find yourself really fighting the tool you may want to think that am I doing the right thing here maybe there s more simple solution only to rethink how going about this that would make life a lot easier so I decided that I needed a fundamental step back and rethink the database design and think how I want to save data into the database so that I can display it a little more simply than having to jump through so many hoops in order to add or if the data into this test results history so I stopped what I was doing on snapshot number four to the snapshot will probably not work completely if you were loaded up and try to execute yourself or Cartwright so I put her menopause decided go back to the drawing board and work on snapshot five where we think the database structure and the underlying code to suck
Minute 9

That so will snapshot number five this snapshot started with me working on the database layout so if you look at the database Explorer and look it out first of all the quiz tabled to notice that I simply added a new description field believe that some public bar charm acts or something along those lines as little as opened up the table definition i see yes indeed it s far from acts and it s also noble and I say that I did was I I made a change to the user quiz table you ll notice that essentially is exactly the same tide change though from the number of correct question
Minute 10

Is to the concept of the score s was going to look at the definition for this table and can see it s a tiny and so this will be of value that will equate to basically zero to a hundred a simple percentage so if there were for example on the 20 questions in quiz and the user answered 15 of those correctly their score would be 75 and that s more in line with how we think about tests in terms of percentages corrects instead of a looking at in no 15 questions correct out a possible 20 and have you do the math in Rome had so that is what I decided to do to take that route again if this is something that is a suit your needs and plenty uses the future is simply added a few more fields to to record the number of phone correct answers versus the number of
Minute 11

Total questions on a given quiz okay so there were several things that needed a change from the previous snapshot or accommodate this will starts first of all and how we re displaying information now notice that I really upgraded the available tests on a data list that I was using from the previous snapshot I essentially a selected the edit template of selection in order to change the item template so you ll see here that I used a hyperlink and a label and although it doesn t really show up as we re working in this item template mode on I set the cascading stylesheet classes so that they ll be displayed in such a way that has that attractive on a formatting that my graphic artist friend of great form
Minute 12

Inc and then basically bound these two are data source and I expanded the data source to include not only the title from our quiz table but also the description which will now display in the description label head Inc and just end to split editing can see to see here that what look like when it s finished as we will run it and then we move onto the test results history you can see now is a much more simplified grid were not have the title of the quiz when it was completed to date timestamp and then finally the score of the twists and to contradict this stick a look at the data source and we have a much more simplified SQL statement now that we work with
Minute 13

We are still going to create a joint in between user quiz and the quiz table but the data that we needed to a select from happening aggregations and so that greatly simple five things Cisco and Castle lists now I d be remiss if I didn t also go before we run this application show you the other changes that were made as well in fact the change that we made affected pre much every page in the site for sample I went ahead and link job the available tests to the start page so that when a user selects one of the available tests it will pull up the start page guide and how to we do this we need to not only sends a request as such Little League
Minute 14

To the start page but we need to send a witch test that the user is interested in taking Solis revisits what we ve done here go back to the edit templates select our hyperlink and to go to the properties and you will notice that the text is a bound property also the navigate your allies about properties as well and I don t really want to to change anything about it if we look at the edit data bindings you can see that the navigate your hell I was able to do a custom binding code expression sews the Senate to start aspx So we ever query string test IDC equals and then we re going to add a eval quiz IDE does he tell statement will grasp the current data item basically whatever values
Minute 15

Are in quiz IDE according to our SQL data source or currently bound to thank Anna will insert that value into this expression signature for the text property were sadly doing and even all titled nothing special tangent here and do the same sort of thing were for the text was doing and even out description that so let s go then rushes to see what they ll look like now priceless login remembers admin and mint tea kettle PAS says fact of your key number one and click login okay so we ll see how this manifests itself you see here that I ve taken several quizzes and here s the results and you can see with the available tests are hearing when I harbor my mouse cursor over a given Quiznos at the very bottom
Minute 16

Will have the is distilled the link displayed right and appear them about to click on and notice that the test ID equals one or the test ID so are our evaluation expression of work just great that s all that work just fine so while we re going to look at next the start page home in just a moment but also won t here take a look at the test result history this was the most recent testify to to notice the score 75 some of these were scores that were saved in the database in previous runs where I ve at essentially you just change the name of the field and so it was still see the number of questions correct not the percentage so you getting nor symbols earlier tests okay so lets stop regular and then take a look at our stark agency will you do to change that
Minute 17

For small think I changed a little bit of the text you re not included but romantic happens in the stark aspx CSS file and this is where I grab the request query strain test ID issue that is not null if it is null to direct you back to the default that is the XML they got here without sending us a test ID but assuming they did give us a test ID them should wind up in lines 28 and 29 here where resistance to grab off the test ID from our per string test ID parameter save it into integer called test ID and then add that to our session so we basically removed are hardcoded number one quiz ID and replaced it with a dynamic value from the default aspx page so that s the major change we made their a single of the questions page in the sure that we made any changes here is his review of brief
Minute 18

Okay primus looks exactly the same incorrect a little problem that we had here in 135 in order make sure we hit the end of the quiz correctly than biggest change came in the results page soul single look at results of its pics LCS essentially school hadn t moved things over here the biggest change was accommodating this new concept of of a percentage instead of an absolute number of questions right a wrong answer was back at her couple lines of code and is walk through this okay social start in line approximately 27 UC first of all we need to calculate the score so we re going to grab the number of questions for the current quiz and got to keep track of the number that are correct
Minute 19

Were going to perform balloon to determine how many are correct and incorrect answer with a loop through each of the items within our answer lists which is essentially an array list cast those too tight answer and then check the value of the results and you ll notice here that you may have expected a literal string corrector ran correct full salute dad about that didn t want to use a magic strings instead chose to change to enumeration we jump over here to the answer CS file go to the very bottom and you can see that I have created a new result value enumeration that I use in my read only result value of rather result property of type result value soar you to return result value correct or result value incorrect or so evaluate that back over here in line 30
Minute 20

E738 if it s correct in all increment correct by one and then we all calculate the score by dividing the correct answers by the number of total questions and multiply that number by 100 so then the next piece of this should look similar to what we did in the previous shot I changed the name from this nebulous idea of test to a user quiz data source and so I set the connection string and the insert command for our user quiz data source changing up on our new score column and accepting use or input parameter set the input parameters of the insert parameters rather just before launch 47 to 50 and then finally to form the insert and the Summit at a small check your
Minute 21

To see and make sure that we have indeed insert rows in a database if not then I have a basically put something on our form that says there was problems saving your quiz results in your database therefore the results from the squid log displayed on the list on the Main menu and where is this error label was to go look at the results aspx page and see a design agency here that we conservative and error label which will only be displayed if there indeed is a problem solos go through the entire sequence of events now auto had run the application will loss in
Minute 22

Test and Tucker would pay attention of slowing to a quick answers to the next one and the next one in conceived acts in the stickler case I went out one correct out of a possible love for a console I also have the sole return to main menu lets see if this particular test is recorded it is and you can see my scores only 25 so that s about it for this particular video shot five at this point we does have some cleanup to do will need to reviews some of some of our code and see if there s opportunities for some exception handling will want to look into what it takes to make our applications in a bowl so that it can be customized for a column of individual users and
Minute 23

Look at what will take to deploy this application and will cover those in the next snap shots in the next video thank you

Video: Building a Quiz Engine 3 VB

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will continue the work on the Quiz Engine, adding the ability to save test results and other functionality. This will allow you to exercise the skills developed in the earlier videos.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

Alooking ourASP net 2 0 quiz engine that we ve been working on and we ll start by looking at snapshot number four hothead to basic goals in the snapshot in the first was to tackle the problems saving the test results into the database so let s set up a scenario for small the user to select which test he wants to take by selecting that will go to the start page and in continue want to the questions aspx page where he ll iteratively continue go through each of the questions answering of choice one to three or four and then when all the questions have been addressed the user is then taken to the results of SPX to this right now for able to display the results to the user of as you recall in
Minute 1

Of the previous video we looked at how we re displaying those results first of all be up to see the question the correct answer their answer and the result weather was correct or incorrect in them by selecting one of the links on the left hand side of the oldest look at the details for the given question through a CD actual text of the question the four answers that were available to correct answer and then the explanation as to why the correct answer was indeed correct okay but at this point we have not saved the results in the database and recall we want to do this so we can provide the user with a historical record of each time they took the quiz and what the results were and then regretted display those results and the default aspx page which is actually the second thing that we want to accomplish in this snapshot so if we were to take a look at the logging view and change from the default B2 20 yeah
Minute 2

Logged in template we can see that we would can be a live view the test results history and this second a data grid ideally these were be able to love you the the name of the quiz the date timestamp when they completed the correct number the number of correct answers they gave and the number of total questions and then ideally there d be another column with a gala view the percentage correct in the end they be able to also bring you all the available test click on one and then go to and take the quiz of Star Trek and the results page because that s where we need to save the the data into the database and the data is in this showcase the number of questions that day I got corrects the date timestamp the username
Minute 3

And the quiz at the organ store all those into the user quiz table and so this is precisely what lines 18 to 31 of our code will do that which is inserted for someone make sure that the user is not posting that this page so in other words if the user of work to click the select buttons over here we don t want our code that saves the results in the database to continue to far each every time it happens so instead we want to make sure that we re not in a post that situation within our page load and tend to do that we checked the use post back property of our page object to make sure that it s false so only perform this code if we re our coming to it for the first time and so this is where now in 23 229 were were actually craving new SQL data source and in the connection string setting the insert command filling and insert parameters
Minute 4

And then calling the insert method to actually perform the insertion into the database focus of the connection string should be self explanatory personally certainly 20 up to this point we ve only seen where we have a drag and dropped I a data source from your toolbox or from the data menu although visual developer however this legal case for creating one from coats of us may be the first time you seen us do that a lease in the series of videos but is very simple to do this we created a new instance of the old guy do set the connection string and set the insert command or whatever command we want to perform what is the select command to delete command or whatever in this particular case were going to insert values to recall the insert command method and paste in a ballot of a insert SQL commands so insert into user quiz the quiz ID daytime complete
Minute 5

Correct answer count username properties and then we have defined what were going to insert in those are the the use of parameters which happen to share the same making the only difference is that their designated with little at simple and so how do we populate those will be skewed through the insert parameters add method for able to reference each of those insert parameters and then pass in the value we want stored to the database so will pull the quiz ID from her session will poll date timestamp from our daytime object we are going to hard code than a 12 inches for testing purposes and then for the username were going to use the user object identity name property in the grabbed a hat and that ll give us the value that such living store within our ASP net TB MDF file for the particular user at a
Minute 6

Call the insert method and at that point it be saved in the database and now the users we will go to the default page can then view the results in their historical record of test results history of Jesus at this point were around to a few challenges and snapshot number for now my biggest challenge was perform a calculation of the percentage correct in this test results history if I m only storing the total number of correct answers and I have a pair that up with the total number of questions on a given test and that will require a pretty hairy SQL query and I think it can be done and I even got the kind of work but then I had to figure out how to perform the percentage calculation either in the SQL query itself or in the control in my little
Minute 7

From data view here and after spending about 1523 minutes working through this neither of those really worked out very well it seemed to me that there must be a better way and that might be a little bit of the tip for you if you re working through problem and it seems like you re really fighting the tool you re fighting the concept that you come up with or whatever it is likely that might be a good time to stop what you re doing and say to my doing this right should really be this hard and that s exactly what I did in this particular case so I often do we think the user quiz table of design to see if there was a better way to represent the data and save the data so could be represented more easily in my test results history so is the first challenge that I came up against on the first multiformat continue want let me show you the SQL statement that I had created in order to use
Minute 8

Current database schema to accomplish this release try to accomplish it is going click configure data source and will briefly walk through our configure data source Wizard and so you can see that we have quite a large SQL statement limit is breaking down quickly for you first of all I am doing a joint between the user quiz and the quiz tables on the quiz ID the most difficult aspect of this is the aggregation the count of the number of roll all the question rose 4 and given a quiz so I do a second joint on question quiz to try to count the number of questions and also pull data from quiz and user quiz such as the title
Minute 9

Of the court of the quiz of the daytime but this user completed it the correct answer count the number of questions that were pulling from this count and so on and then I had to get into this room by an having statement in order make this the kind of work and before you knew it I had a pretty big mess on the hands in fact this point out of the group older can parse through it maybe can hear do so at any rate to it that can t let the results were not favorable so I ve decided that there had been other way around this so that was the first clue that I hadn t made any the setback will the second part of that I needed to us rethink was what I wanted to display in the available tests it was easy to find just the title of the given test I m also need to make a hyperlink for so I can click the title and then be sent to the start page amount of past
Minute 10

A some type of variable from default to start so bad I can let the start page no which test the user wants to take so having given that some thought I might have to change of Powell model data list your works and going to want to add in another piece of data may be a want to you will do more information about this test more informative than what the title can indicate so I may want to add a description field to my database so there was enough that I needed to change that I need to stop or I was at and decide that I was going to end snapshot for a little prematurely a backup and change things for snapshot five so that I I could achieve the results are really wanted to so that s ongoing to do at this point okay so after an hour or so of
Minute 11

Were looking at snapshot number five the very first thing I did was made some modifications to the quiz out of me if I ll specifically listen to look at the quiz table he must go ahead and hand over the table definition and you can see that I basically added a new field called description which are made of our car max and allow it to be known so this will be included on our default aspx page after the user logs in its available the more descriptive text about what this quiz is all about their full and close that and then let s take a look at the user quiz table where we made some more changes at the table definition for this and the basic change enemy was purely conceptual I changed the name of this field from something like the number of correct answers are some more lines to simply score and score will represent a number from zero to 100 in them will think of in terms of percentage so
Minute 12

Sample if there are 20 questions on a quiz and the user answers 15 of them correctly and status of of storing the number 15 into our database for in store the number 75 because 15 divided by 20 is 70 54 7 575 so will will change what this means from a purist of a number of correct questions and answers answers to more business for bases because whatever we think about test scores in those terms and may not be so pertinent for us to remember the actual numbers of questions right and wrong things of that nature so that was the final change we made to this basically just a name in the intent of one of the columns within our user quiz at the table
Minute 13

The results page because Livermore fourth limitation of this now Ashley listen to look at the results aspx WB page and so we modified the code bat that we formally had lines of a blooper was like 17 to 31 011 22 320 I guess the end of that method we ve added some additional code here you see that first of all were going to calculate the score by obtained the number of questions for the current column answer list you recall this is our array list that we been storing in our session object that we pulled out a little bit earlier code so alone from the previous 30 had were work wrapping our array list from the session object we can account how many items on the answer items are in our array list and really create a verbal call correct
Minute 14

So that will allow us to determine how many answers were correct and so long as 29 through approximately 35 or even determine how many correct answers versus how many incorrect answers every time we find a correct answer were going to increment our correct variable by one of how we determine whether an answers correct or not we ll socially were going to live through our answer list and for each item in our dance or list for in a converted into back into an answer object and then check to see if the current results is equal to this answer result value to correct note what is this it it it s basically a replacement for those magic strains that I had within our own within our cancer class Lessig would answer the teachers briefly scroll down to bottom of that and notice now that instead of my result property my
Minute 15

He only result property returning a string of correct or incorrect notice that in lines 47 to 50 added enumeration called result value either correct or incorrect so that is what s being returned from our result property and you should always try to use enumerations rather than use a just on hardcoded magic strains as a call of insular some degree of consistency won t have to worry about misspellings and things of that nature shall strongly typed also back your risk and see if our results on property for the current answer is either correct or incorrect was corrected for going to add one or a correct count and then once we determined it and finished looking to reach answer were going to calculate our score so Tim scores double and will take the contract
Minute 16

That by a hundred and that will give us the number that will store than in our new score column in our user quiz table so in lines 39 through 46 should look very familiar you we change that we may hear it as the name leave we change from the work has two more descriptive word for our SQL data source for calling user quiz data source we also won 41 were craving the insert command we change the column name or rather we should have changed this on the go and do that now to score was going to make that change here as well and then changed this discourse of August overlooked a few things here use to strain all right and finished and see what
Minute 17

Be done here is caller insert statement at this time are going to bomb out retrieve the number of rows that were affected if zero rows were affected once we call the insert method if that means we had a problem summer in a display this somewhere on our own results aspx paper based goodness it is from senior quiz results in the database there for the results from this quiz will not be displayed in the list a main menu analyst go ahead and take a look at where a where those will show up in see here we have an error label and that will actually contains some text only if there was a palm saving things into the database also notice that we have a new link return to main menu and when the user clicks this now will be a look at the historical record of their own
Minute 18

_solicit a look at that next face on a OPEC default aspx of the design do and so right off the bat noticed that we have changed a little chattel list that contains are on of the available tests notice now that there is a hyperlink and the second rule of area underneath which will contain our descriptions let s go ahead crack that open and take a look at the edit templates where we ll see the item template and what I ve done is drag over hyperlink which is within him for look at the properties for this agency has a data bound property of text and navigate URL solicit a look at the bound properties for this edit data bindings notice that the text property has a custom binding expression even a title so basically to
Minute 19

The current data item according for SQL data source to current item and buying that two of the title property of our or data source two of the text property of our hyperlink and then more importantly those fortunate you to navigate your oil we need some way to send a indicator to the start aspx page of which test the user wants to take it away chosen do that is through the query string so I ve modified the custom binding code expression to basically start aspx notices are That ll be our query string indicator test ID equals and then we re going to use eval quiz IDs for Bennett s Senecas IT curling up to quizzes one or two as many as we possibly could have that ll be added so that ll be the navigate URL once the user clicks on
Minute 20

One of the hyperlink hyperlinks and cancel that and then let s look at our description table and at deadlines for that notice that were simply just using the ego description the new field in our database and cancel that as well so did and template editing we can see now that we have him a a list of available test is a little bit more what we originally had in mind will have the title which will be hyperlinked and we click on the hyperlink of brings to the start page and in the description for each of the available tests will come back to dislodge the moment but let s continue on to look at the test result history and see that we clean it up quite a bit now will does have a quiz column which will contain the name of the quiz the daytime completed and then finally the score recall this will be a score
Minute 21

In terms of percentages so this also greatly simplifies our secret data source and click configure data source and take a look at the query it will need or still go ahead to join between quiz and user quiz in order pull out the title of the quiz the daytime complete for the users instance of the quiz the score from the user quiz and so on but because it is greatly a simple fight a result of our or database change a faceless go ahead and give this a shot of a run this just to see how far we ve come okay so let s go ahead and try logging in MS username paths that were won as our password and click login and now we see we have are available tests are formatted the way that we wanted them with
Minute 22

Our little links here that gives some of response where we have our most for sure limits results of the CSS that we that s a graphic artist great for us and also a description of each of our available tests noticed that when I hover my masters are over one of the links in the status bar that we have the query string of tests that equals either one or test ID equals to was committed to the concept in just a moment and look at how supplemented on the start page also never test result history none of some these early tests were as a result of some mob of the oval old code river keeping track of the actual number of correct answers now in these last two tests we ve mood to percentile where we ve actually got as you see 75 correctly for this particular case okay so now when I click a test to take it again from the tickets Bridge of death death test now I
Minute 23

Come to the start page started his PX and passing in as a query string test that equals one the hottest star page know that that I want to work with test ID equals one was a do with that information while before we go on the school had look at the ads so were to open up the start aspx VB page and look at the new code that would add it here notice that were testing to make sure first along 123 stats are query string is not empty so we don t want to allow them to go any further if test ID equals nothing will send them back to the default aspx page however if there is something in our test ID a Christian parameter number going to stave off that value as an injured test ID recursive out of the request a query string to study and then in 125 and add that to our session of reported have this code hardcoded to the
Minute 24

A new one now we replaced that with the dynamic values that were pulling from the query string at so that s how we make that were close to one or more time and code put it through its full paces here will go through admin pass at were one and click login the symbol to be what s next of Microsoft quiz and will distinctly get one or two of these correct language you can demo the Senate looks of it three out of four correct that s great was returned the Main menu and this will show us our test history as the most recent test we took any conceive that it indeed was completed on the state and the score 75 pace or getting very close to the functionality that we originally desire whatever we were designing our application some of the things that we need to do our revisit the code and make sure that we have good exception handling in place will want to just comb through the code measures will
Minute 25

And it will want to add some skinning features to the application so that the user can select a different skin Tom and then also will want to lump talk about how to deploy this application out to our Web server so that will conclude the snapshot number five and conclude this video will pick this back up in the next video I keep

Video: Building a Quiz Engine 2

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will begin to lay out the web pages for the Quiz Engine and create some of the initial code required. This will allow you to exercise the skills developed in the earlier videos.


Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video

Minute 0

It is your start looking at the snapshots for the development of our ASP net 2 0 quiz engine but just recap the previous video a snapshot is the present state of the application at a given moment in time to reach our to development on the stop working or save off the current state of the code and then I ll explain what is accomplished soon this viewer to look at the first three snapshots the first snapshot took about two hours and what I accomplished during that two hour timeframe well as you can see here I ve added a number of pages to a project we have the full page to questions page recover password results and starts to look at each of these recover preferably the start page
Minute 1

And then finally the results page and as you can see the each have kind of a similar look and feel of basically created one as a template use the table for layout purposes and then copy that table from page to page changing the graphics and some of the text in each of the pages the graphics I used from what my friend provided for me the graphic artist for some of the the titles like the results of this starting quiz now graphic question graphics so one as I merely just with drag and drop from the images folder each individual item into place on my little table template files over to the exercise of applying the cascading style sheet that my friend graphic arts critic for me as resolve the previous video and applied that every control
Minute 2

And the taxable see this of a primarily within the default aspx page where the Texas I typed in Persepolis will login a passage here as well to all the text in all the given properties that modify the very language aspects of each of the controls of those had to be modified to a loan to the cascading style sheet tags that were great for me and that is a considerable amount of time to go to locate all those properties and change them appropriately but if the majority of the time on the default aspx page and what I decided to do here was combine several the operational elements of the site onto the single page and I did after the use of the login so if I as we saw mocked out there were different pages for login for register a new user and then ultimately the default page where the user can see their test history and the available on a cat
Minute 3

Us that they can take what I did was combine those all together into a single login views what you re looking at right now is the view of the page as a user comes in and is not authenticated have not logged in yet once they successfully logged in to the website however we want to do is in display the logged in template which will show the available tests the test result history of allow them to perform some basic account maintenance like change the password and so on solicit a look at what this accomplished local go ahead run button to start debugging button on our own or a toolbar and we can see our application pop opened for going to login using admin
Minute 4

RG and then the number one so uppercase tea lowercase a access the asked symbol lowercased WOR TV one so passed at were one and click the login button and then our login view will display the available tests the test results a stream so one is see here we have our little on a control that allows us to see if the current user or we been able to change that tax based on whether or not they are authenticated and so on and we do that through the use of this login name control to limit also have a lot instead is controlled allows them to your login or logout based on what authenticated are not currently on the site so basically what we did was just tackle a lot of the easy stuff first answer to ease into the development process saw essentially create the skeleton of the application in
Minute 5

Out one of dive into some specific parts of the application and more fully flush them out and so the next thing that really felt like I needed to do was address the database and real look at that in the next snapshot sewer currently to look at snapshot number two and the only thing that really did with in the last half hour 45 minutes of the snapshot was to create our quiz MDF database and in that database I added three tables the quiz table question table and the user quiz will take a look at each of these tables in just a moment talk a high level about the relationship between the quiz MDF and the ASP net TB MDF to recall this file is four for more produce discussions while it s the database that will contain the values for the membership rolls
Minute 6

Of functionality within it has begun it to auto whenever we go to the aesthetic configuration tool D website administration tool and click security and go to manager users and looked Re at a user called admin here that that data in the roles that that user is associated with are stored in that ASP net TB MDF file or go to want associate certain elements of our quiz back to the users within our table we are within our guest event DB MDF file particularly each user will have the historical results of the quizzes they ve taken stored within our quiz database Cubs taken these three tables this question quiz and user quiz tables and add them to the ASP net TB MDF file I think I could ve done that now just for separation purposes because also comfortable with modifying the file just yet I
Minute 7

Decided as a design decision to keep them in their own MDF file as ramifications for that decision and I ll point those out in just a moment but until comfortable with changing or adulterating this automatically generated ASP net TB MDF a file because again working with a beta version of the software and as we all know things can change out from under us additionally had a moral lock myself into any specific implementation and case in future versions of the software the database schema changes so that s just a design decision I made it was a difficult choice to make however it s one that I may know how to live with and there are some ramifications I noticed a moment ago not the least of which is when I try to associate back all the values the historical values for a given quiz for a given user of the less first multi look at the quiz table
Minute 8

Very simple straightforward simply a a primary key called quiz ID and the title of the quiz and we may well come back to this little a little later in a future snapshot and change or add some values here so that we can guess more scripted text about a given quiz does the work for now each quiz has a number of questions that are associated with it here s where another typical design decision came in below here that we see some typical stop the question ID the primary key at the very bottom had the quiz ID which is the 14 back to the quiz tables of quizzes will have one or more questions associate with them you ll see that there is the title which will be the actual question and then there s a series of answers one to three and four and this is where the difficult decision came in the database designer within me felt it would be appropriate to put the answers in their own table the software developer and sodomy decided that it be easier if I just Dean normalized them back into a very ominous wharf
Minute 9

Last structure for my table and put each of the answers in their own given columns make it very easy when I go to pull those answers are the database to the display on my question aspx page now as a result of that design decision I basically locked myself into a certain specific implementation of the words ignore the multiple choice and there have to be essentially for her questions there can t be farther campy 30 or rather answers that only be for answers ABC NT and so for my purposes in this little application that works just fine however it s less than robust less than feature filled when compared to some commercial versions of quiz engines that are available on the market today but it s a decision that I m going to have to live with for this time so eerie we have the
Minute 10

Available answers in this holds a saying that goes something like this normalize until it hurts denormalized until it works so I ve decided to take the latter route and to normalize those symptoms to look at it in the correct answer which will be the one to three or four the answer explanation which can be any long screen that explains why I get an answer is correct or incorrect the ordinal value the question orders so a given quiz has a number of questions this will keep track of the order that those questions should appear to the user and as we boarded looked at the quiz idea to foreign key field back to the quiz to not is a look at the user quiz table this will again store the historical results of a given user taking a given test so many of these fields are basically for associative purposes the user quiz ID is our primary key we have two
Minute 11

ID which associates back to a given quiz and then the username with associates with the ASP net DB MDF and if we were to drove down and take a look at the gift tables there is a table called as peanut users and within that there is a field called username so this will be essentially a non relational database and forced constraints so we ll have a of enforced this can strengthen our own code because SQL Server doesn t necessarily six first edition does allow constraints across multiple databases and if it does then it s a fairly complex procedure soul merely just do this well in code which comes with its own particular challenges it will really pay attention those at this point but that s essentially how were going to associate a historical quiz with how many correct answers of
Minute 12

Were from bad to that the quiz session and the date and time that the quiz was completed okay so that finishes up the second snapshot I remove on the third snapshot and try to take a first crack at some of this functionality is so you re in the third snapshot missed him about another hour and a half hour 45 minutes or so and my focus in this snapshot was to I get the process of displaying and retrieving the the questions and the answers are strictly from the user and sold most of the work that I did in that task was project that we reviewed in the previous video really came into play here if recall from that discussion we had to make a decision about how we re going to store the information from question question and others number of different ways of going about it could distort the values as a user goes for question one
Minute 13

Rushing to the question three for a given quiz could have persisted those within the database persisted them in XML or there s a number of ways we can persisted them in memory such as the view state object but we chose to use the session object because we ve been assured by the Senate to a team that this is something that we can rely on it will not be heavy burden from server perspectives or going to ahead and use and also we know that for our purposes is not to be a very high traffic website and quite honestly a more complex augmentation will take a lot of time a luxury that we simply don t have this point so there are three pages are involved in this process to start page questions page and results page user will start on the start page and the start button to get started with Clinton to look at the code behind and see what happens magically on this page personal notice that we needed some mechanism to hold onto the answers each
Minute 14

Asserted that the user gave so and we know the restored session but basically where did I came up with this solution where I want to use 18 with domain specific object class called question arms are recalled answer to save the values of each individual answerer that will then collect out and review on the final page the results page so close to start here the answer class has a question ID the correct answer and then the users answer in a read only property called result which will displace either contractor and correct depending on whether the user s answer was equal to the correct answer sold basically be using this object this answer object as its created after each question is answered by the user and added into a collection or use an array list
Minute 15

To store oldies individual answer objects at the very end of the process of of going through in and answer each of the individual questions will essentially iterate through each of these individual answer objects in our array list and then read the display them to the user and store them in to the database that so we re going to use this answer object beginning in the questions that is just paid for it if you re when you do first is to basically says to Emory aside for a new instance of our array list which were calling answer list and then we ve also created another session variable called the quiz ID and this will be very important as all the mystery here on the questions page okay so again for more discussion in the test was project which was sort of our scratchpad for coming up with some ideas of how will
Minute 16

Delay and allow the user to interact with each of the individual questions in our quizzes him that we re going to take slightly different approach than what might be out there normally just for brevity s sake and since we re going to use a detail view to display the question and the four answers and these will be displayed from our SQL data source and look at that as source in just a moment and then the usual be able to select the rancher from this combo boxes drop down list if we were to select the little tasks aero and select edit items you see that we hardcoded database or 1234 and the values are respectively one to three and four and those will be evaluated against the correct answer at the end of the process and cancel that for now and so Lessig look then add the question aspx VB and look at the page load
Minute 17

Is to have question details data binds all that happens there so the question comes in how does it know which set of questions to display we haven t told it what what quiz of the users currently taking and also we need to tell it at some point as well what the next question is a should be displayed to the user so both of these questions can be will resolve in how we implemented the SQL data sort go and click the configure data source select the next button and click next again and here you can see that we define a custom select statement solo question ID title answer one answer to registrants for correct answer or shorter from the question table where the quiz ID equals as parameter at quiz in that order by question order so high we send in this
Minute 18

Parameter this quiz ID will this were the the configure data source was erred in it s really cool and that is through the use of our session quiz ID measure recall in the a stark aspx thoughts VB page that we create a new session verbal culpas idea and we hardcoded this point to value one will change that up in the future but will hold from that value here in order populates this parameter so that s one of the neat things that doesn t require a lot of code we write were able to wire that up fairly quickly and easily just aren t referencing a given of a given field of our session object now we could ve grabbed that value from a cookie from a control from a form from the profile object
Minute 19

From query string however we chose to go the route of session and so on to choose the appropriate field and go him to cancel here so one big changes to that so as the page loads the SQL data source will look for the the quiz ID parameter find in the session retrieve all of the questions for this given quiz and then display the first one in our little at details view grid user clicks the next button was going to take a look at the code behind for the unwashed click event essentially what we need to do is create a new instance of our answer objects and add that to our answer list array list so here were doing is creating a new answer objects are our answer object looked old ago to test the
Minute 20

Properties question ID correct answer user answer in a read only result answer a pencils to back your recruiting of this record the question ID which will pull from the question order from the current row of data in our question details to the current data item in our a detail view control regret the correct answer is well from that from that data row view and then grabbed whatever the user selected in the answer drop down list Marina do is retrieve our answer list and add our new answer to it and then save it back in the sessions organized grab down plot the new answer and save back in the memory finally we need to tell of the next
Minute 21

Age what it should be displaying so again we want to set the page index for our question detail object that little grid for her that will display the details so based on the current page index and the number of pages that are in our rather retrieved by her data source and will either increment the of the page index or will just do a response redirect to the results noticed if it got so also take a look at the results of its guest page is fairly straightforward first thing that we see here is we talked a grid that will display each of the individual question numbers with the correct answer was with the user s answer was and then weather was correct or incorrect when the user selects an individual row to review the answer to display the question over the question
Minute 22

Four possible answers the correct answer in the explanation all pulled from the database of this data would be pulled directly from our answer list data rate was that we been holding onto her session object when the user selects one of the rows will combine it with the list of questions from our question database so will filter was displayed here by the selection care how we accomplished that will most take a look first of all what we did and select the edit columns to concede that we just created a four Brownfields question correct answer your answer and result making sure that the data field is set correctly to what we called it in our answer objects and these are all properties of our answer object user answer seas will be bound to automatically by ASP net shadow
Minute 23

Colt s cancel that somewhere is a select column comparable really to look at the properties solicit a four close first Citta for a keyboard the brim for properties window and you take a look at this auto generate select button set equal to true that s what adds this selects column here with you one other thing in that it is to change the on let s see if an owner ago Jackie James feels it has to be said to assess what is the equivalent of the primary key in this case is going to question ID the unique identifier that separates one question from the next question so in that case within our answer object that s the question ID field so that we select one or will have a unique result will be displayed below okay so now will save a look at this sequel data source is really nothing special is goes on to
Minute 24

At all what is retrieving all of the columns except look was that he was a big mistake to come back and fix from the question to cancel that and will no tear that our details view is then bound to does data source or we want to display just any row from our data support source we only want displayed the role that was selected here in the select button column on our data grid house that accomplished was to go look at the results for you to and look at the result grid_selected and exchanged event will see that we apply a filter expression to the SQL data source said that that he feel that question ID equal to whatever the selected value was of that grid so give her pulling weather was one to three or four arrests and mats to this the
Minute 25

To expression for only this way a corresponding question with all the answers correct answer all that information here in this grid solo single in the salesforce okay so here we go where going to run our application and get the start page to start button and so we ve got a bunch of silly questions that I just entered for the purpose of testing this from a famous Monty Python skit soulless start selecting some answers to some questions here click the finish button and we can see now how many answers are correct and incorrect with the correct answer was versus what our answer was and then by solar
Minute 26

Ping one of the items here we can review it here in the bottom along with with the correct answer was in the explanation for that given item okay so everything is coming along very nicely made a lot of progress here s a couple of hours for some refinements that need to be addressed and sold to do in the next video or two as we continue on looking at further snapshots or we have left to do actually got quite a bit to do first of all we haven t really recorded any of the results into the database and remain to do that here in the results aspx page then we haven t displayed in the default aspx page would have displayed on any of the and political theater s go to the login template this still need to be fleshed out the available tests to test result history and so on so got so credited to want at smaller features as well
Minute 27

But were also great start in sword and conclude this video for now thank you

Video: Building a Quiz Engine 1

Presenter:Bob Tabor (from LearnVisualStudio.NET)

In this lesson, you will begin to see the creation of the Quiz Engine. This will allow you to exercise the skills developed in the earlier videos.
Click here to go to original video page

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video



Minute 0

In this video were going to begin developing the quiz engine that I ve been alluding to for many the videos in the series as a hawk was put in practice all the things that we learned over the past 10 videos and visualize how all the pieces come together to create real working application outlines the size of the purpose of the next four videos is to demonstrate how to build an application from start to finish from concept to deploying it on a Web server and a one start off by talking about the process that really used to develop this application then starting in the next video will begin developing the application and I ll be taking snapshots the development process each hour or so to demonstrate how things are coming along of this application will take several hours to build and most of the process can be very boring so instead I m sitting at the highlights much like a watching the evening news review the highlights ofwill be okay so each point during the development you ll be able to download the source code
Minute 1

Look through it and it got warm explaining you be able to see what I ve done during that snapshot of a soulless top of the process will use to develop or application under a lot of different formal software developer processes and most of them are designed for multiple developers within a corporate setting one popular crosses was created for this purpose is called the Microsoft solution framework and it outlines the steps that are required to build an application with multiple team members in a corporate environment and ultimately the Microsoft solution framework or MSF for short boils down to some great basic steps first you envision what you plan to build next you start planning to build it in 30 start developing the application courtier plan of the fourth step is testing in eradicating any bugs in your application and then finally
Minute 2

Of these five steps are repeated several times were given software to build the project each repeat of these steps is called an iteration so think of our time together in the next four videos as the first iteration in the development of this quiz engine and perhaps at the end of the series you might want to take on additional or rations to expand functionality and perhaps make it more stable improving it based on input from your users not in the MSF there s lots of steps or not the fault what creating vision documents and formal requirements documents and so on says were really just doing this recreationally were not gorilla worry about doing all that Diskeeper mine though if you someday work for a company that employs a process it s not going to be just as easy as imagining some cool software project and then starting to develop the code that typically weeks or even months of envisioning and planning
Minute 3

Than before the first line of code is even written but again it s just you and I agree this fun little applications or not worry about all that still wouldn t want to be somewhat structured so we have a clear idea what it is really building its own so let s start with envisioning our solution as I stated at the outset we want to build a quiz engine in other words we want build application that allows users to first register on our website to take one or more quizzes than allow them to take the quiz which for an hour just going to multiple choice ABCD style questions and then the users we will review the results and have the results saved so they can see when they took each of our quizzes and what their results were additionally I will make this scannable so that other people who might want to use my quiz engine can easily integrate this into their own website by merely changing the style sheet the graphics and so on
Minute 4

And finally we re why create a very simple quiz entry screen so that I can administer a great new quizzes I has similar goals and crating misapplication of for starters I were trying to utilize as many of the new features in ASP net two it was possible of course only when it makes sense to do so and so you ll see as we begin to develop the application of this might effect some of the design decisions that I make also another goal that I have is that I want to try and write as little code as possible of these may not be realistic goals in the real world you don t always get at two to just change the design of your web application to suit the toolset that you have Jordan for a client or for your company they may have certain things want something to function in a way that s not always supported in the most direct way by your toolset
Minute 5

That s a luxury that I have and that you may not when you re working for a for client or something else and also since register was recreationally we don t will worry about decisions that may affect the scalability of the application on an assumed on Korea s application for a low volume website and I ve worked on projects that require a lot of attention to scalability because the client was expecting potentially thousands of concurrent users so again this is a luxury that I have that in the real world may not really work I swear to be aware of this the purpose of our project is just to see many of these ideas are we discussed the greatest and lessons come together in one application and maybe this isn t quite as usable in the real world in a high volume scenario as we could possibly make it but a war for our purposes today so back to kind of our structure envisioning the solution involves having a vision
Minute 6

I like to build an application that does XYZ not as clever not really designing application were just make his mental notes about the things that we like to see in our application and now that I have some mental notes on the need to solidify these into more concrete checklist or requirements list at this point on the start jotting down some thoughts negotiate paper or white board and again I do want you to formal your eyes would create us for fun other was a Michael Bopp is differently but as as begin the job down some notes this list of mine includes for small allowing the user to login to create a password to retrieve their password to change that effort just a basic membership number should so that we talk about unless and not mess after the users able login she should really see all of the available test that she can take next the user should also be able to review the results of the tests that she is
Minute 7

Taken in the past in some sort of tabular fashion about when the user clicks on a test to take it she should be based within the test page or shouldn t see the first question and all the possible answers a DC indie and so pick one of these and click the next button are you seeing the subsequence before Alston on the final page soon we will see the results of the quiz in some sort of tabular display and to build a click on one of the questions in that list and be able to review the question and the explanation for the correct answer somewhere in the St so as I begin to list these things out notice that we subtly move from envisioning phase 2 of planning and design phase in our project is at this point I need to start thinking about how Nepal is often a technical perspective at this point I m probably going to start drawings and diagrams to help understood an
Minute 8

And the basic flow between the pages on my site and this helps you visualize how I want the application war I also might draw the layout for each webpage I can see where the data will sit physically with HMI makes and notes to myself but how once immune function and so I call this a low tech mockup is basically get dry ocean paper on a white board and since this is a web application and I want to look at it to look very attractive I might ask a friend who s a graphic artist if you be willing great mockup of each page for me now I could do this all myself but really I m a developer and I don t have the eye for design that my friend Dustin has some explaining in my goals on the show my notes and then we start to hash through the page flow and the layout of each page and so he is able with some ideas at this point are working for client I would show them these mockups to help get a night
Minute 9

A delivering to them and to help them see my vision and is a lot easier to get feedback now than once I ve finished writing the code so but in this case is not an issue right towards developing this recreationally forestalls Sosa look at what dust in my graphic artist friend has helped me to mock up fairly quickly so here s kind of a master page that he created so I can click on each of four page designs first of all we have the login page and that should be fairly straightforward no really use the ASP net 2 0 logins so this may not be so applicable but we would may be able a evidence of these design elements like as a line and this this had bar and some of the text as well while to rethink through that then this main menu is really help we can see here that we have them missile tests of the top with the name of the person is logged in the option logout
Minute 10

In our little title bar of a list of available tasks is nice also been the test result history in a table just have one entry here we can see you know how many questions and what the percentage correct was when was completed in with the name of the test was so that s really helpful I think that is something we can accomplish then the actual result page may want to rework us a little bit you can see here that time are we able go in a column in our list of of the question was right or wrong I may want to expand sold it but he gives me something to work with I can think through some of these things I may not use the same colored Texan things in nature but it gives me an idea of of what I can like to come Bush and then finally here we ll take a look at each test page 40 of or rather are going to talk about some reasons why this may not work from a technical perspective based
Minute 11

On some of my particular goals but it does give me a good idea of the layout on trying to achieve enemy that it will copy all these designs exactly but since I asked him to keep it simple I can get this pre close but his work is deftly helped me get a better idea of what is on the rebuild the what is going to build an now starts helping me focus on the technical things and when you do to make this all happen so for me it s back to the drawing board and to continue make some notes and some tries and things up and so as I start thinking through the development of this application I know that all the membership related tasks will be pre shrink forward based on all the talk about lesson nine part of a piece of cake at max any think about how to display each of the questions and potential answers on the questions aspx page
Minute 12

Now I know what I would like to do but I m not sure that the A s given it to that of data controls can support it web like to do is use the details view control to display the question and each of the four potential answers now I know I can data bind those in their the part I m not sure about is whether or I can edit the template and insert a series of radio buttons and there s well so to answer that question in my own mind about what I ll do is pop open visual Web developer and create a test project where I can work through some of these ideas solicit ahead and take a look at missile test quiz project that I created using C sharp again I did this just a test of theories and some ideas this will not be the final project in fact overthrows project away at some point but I would be alert a lot by going through a couple of exercises your tests and theories know in addition
Minute 13

To working through some of these examples in the test project I m also going to a couple books that I have and even go to the help system and maybe some examples online to try and find any examples of what I m attempting to do unfortunately after a couple of hours of searching I don t think that this ideas that works on it to move on from there so I start exploring the idea of binding a radio button list the questions answers but began after doing some testing it doesn t quite jive with what I had my site have to move on I start thinking about controlling all the data access in code rather than trying to a data bind everything and while that might be the approach that I take if I were doing this for of a website that is expecting a lot of traffic soar to control everything works a little bit more precisely on the resistant urge for now it would take
Minute 14

Us this is few lines of code as possible schism was creating an application for fun I briefly think about taking the easy way out and using a wizard control of TCP here to see this will test so it uses Wizard control to greatest series of panels and based on each panel every time I want to create a new quiz I would need to come basically go in and add or remove wizard steps that each was a step on the create new controls and each time the user clicked the next or previous button then they would me we need to evaluate about as a control strictly through code so basically while the navigation would be dull for me a lot of the processing of whether things were correct or not I had to manually code for each and every test I create
Minute 15

Pill is never a good idea because I have 10 tests on why create 10 different webpages and created new webpage each and every time I created a test some of that stuff should just be data driven which was my original vision so while this is a good idea in the process of playing around with this four hour so I got a chance of the rows with some controls I was a bird familiar with Psalm online that was still a productive out work to spend so after a lot of soul searching Kriegel tests I settle on a strategy to bind each question and possible answers to a detail view control so this is basically the little test that I came up with and essentially I d be using the drop down list box to allow the user to select their answer whether answer 12 career for
Minute 16

And then they would click the button to go to the next question about the downside of this is that this is not a standard way to create a test most people are going to be more familiar with using the radio buttons down the left hand side of the line to the various questions and realizing this as you see I briefly start test the possibility displacing radio buttons next to where I think the questions and the answers will be rendered by my details view control now the only problem with this approach is that if a given answer or the question itself is still long their raps down to the that would offset every one of the radio buttons that would be quite the right spot so for now I m just decided to do to move forward with the drop down list box will select in a one to three or four and then click the next button
Minute 17

Continue on and after it s a feedback from some from some users and biggest complaint is this unusable then I might revisit this spot before icing too much time into a lick developing the ultimate solution I m screwed ahead and move forward with what this first I do that I have and third I m starting to flesh out the details around a data structure now my original thought was that I would store the questions in an XML file but there were two concerns about that I had a first the more begin work with the XML I realized it easier to have a quiz in question data in a database so it could easily crew relationship to the quiz results for each user a yes I can still may work but is where my own personal biases come in on missile will more couple working with databases and XML files at this point in my career so I offer the database solution over a
Minute 18

Jamel my second concern for XML was that it would be fairly crackled bowl in other words if somebody discovered my XML files URL they can potentially do pop it open another browser read all the answers while they re entering the quiz but while this little application building is not intended to be testing software for certifications and so on I still want you will walk is down from potential cheaters saw Mystic with the database solution right now so get out of sheet of paper are white for a start mocking of my ideas on the design of the database that allows scratching out comparing it to my mockups to see if the right data is being saved or retrieved from the database for when you display or sit back and now finally I mean think about how the database state between each of the pages specifically the pages that deal with saving what the current selection of the user is and
Minute 19

Putting on to the next question so restless lot about saving each answer to the database in a table called something like user answers so each time the user clicks the next button it would save their answerer for the current question into the database with their associated username and the current question ID but after thinking to rule while I decided that I really did need a store that data in this first ever ration I m not allow people a review of the stroke will record all their tests so that we will go back and look at the answer to every question that they gave also I wanted to get the database each every time somebody answers a question so tried you ll more conscientious about the resources for my website so I consider storing everything in the profile of the user
Minute 20

Pic is meant to store more permanent settings not temporary test and so I settled on storing the answers to the test in the session object now in the past your scourge from using the session object too often but even though it really made life a lot easier and the reason you are discouraged from using the session object was due to memory consumption on the server that was required by the session so we will store some predict things into the session and I will take up a lot of the memory of the server of slowdown the website is a whole in fact at some point in the past with classic ASP and that refers to the days before net came out the session object became a four letter word in developer circles however when ASP net came out of the session was fixed and were told that it s even been enhanced and is the attitude of similar trust be a has been edited out a team can rely on the session object for storing the data is storing the state
Minute 21

As I go from one page to the next no it won t really become a problem unless my site becomes incredibly popular which means I probably would need to revisit this application and test test test to find a better solution but again the session is so easy to use as the one of saving a lot of time and saving a lot once a code so that it is really the last decision that I needed to make a point seen one and I have really documented any of these design decisions that I ve just been talking about again of our working with others especially morphed a formal setting on my one single time here in Rome these ideas by my coworkers maybe go through more formal design process for creating diagrams and things of that nature are however in this case some simple mills on a sheet of paper or the white board will work just on okay so I have what I need to get started on the start by creating new project on the ad
Minute 22

It is a to the project that I need in them and make sure that all the membership functionality to login and creating a user and so on works metadata from the start with a harder tasks I ll correct database and a hook it up to the questions page in the results page and so on so now that I ve gone to the envisioning phase and the planning phase and design phase Malamud turned my attention to the development phase so we ll pick that back up in the next video thinking