Poll
Summary:
The control is based on a database. Each poll in the database has its ID. When initiated, the control searches for the specified poll, or searches randomly. Then, it loads up the poll's options and status. It shows up a box, with the poll's ID, options, question, vote selections, owner, category and two links for voting and seeing the results. When the results link is clicked, the box refreshes to show them and provides a link to change back to the poll - vote view. When the vote is clicked, the selection is saved in the database. But to vote, the user must comply to the poll's options (free for all, authorized only, multiple voting or not).
Click here for an image example
...More:
If the page is postbacked, the pollID of the control doens't change. If it's not, it searches for a pollID. When searching for pollID: If it's a random id poll, it searches randomly for an ID (option available for showing same poll ids or not). If it's not, it shows the poll id assigned to the control.
If the control is visible, it continues further functioning. It opens a connection to the database and retrieves the info for the poll, creating a dataset and a hashtable (for the poll options such as multiple votes).
Then it creates the box that is showed. Firstly, there is the poll id (if it's random it also shows the word "random"). Then the poll question. Then the main poll page and finally the two links for voting and seeing the results. The main poll page is, firstly, showing the selections for voting, the category of the poll, the creator of the poll, and the date of creation.
When the Vote link is clicked: If the poll is only for authorized users and the current user is not authorized, it shows an error. If the poll doesn't accept multiple votes: It searches the text file of the polls to see if the current IP address or username has already voted for the poll. If he has, an error shows up. Otherwise, the vote continues: The database is updated and if the poll doesn't access multiple votes, the username or IP address is written to the polls text file.
When the Current Results link is clicked: The main poll page is refreshed with the current results in percentages and small tables for showing the results. A link is also provided for hiding the results and getting back to the main view.
Properties & Specifications:
The control inherits from the Control class.
DbConStr | String | "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Context.Request.MapPath("Files/TextFiles.mdb") | The database connection string (oledb) |
MaxSelections | Integer | 9 | Max poll selections (must accord with the database fields). |
RandomPoll | Boolean | False | If the poll must search radnomly for a poll id. |
PollUsersTxt | String | "Files/PollUsers.txt" | The text file where the users that have already voted are written for the polls with no multiple votes. |
|
PollTableUp | The upper table of the poll. |
These styles are found in the Styles.css file in the Files folder. You can modify it, but you have to copy according to the Install Instructions.
Poll Users Text file
This text file is needed if you have polls with no multiple votes. It is specified by the PollUsersTxt property and ASP.NET must have access to write in it (go to the security panel, and add the ASP.NET user with write access). Should be blank at first.
Database details
We strongly suggest you use our database.
In the database there must be a table "tblPolls". The required fields of the tables in strict order are: ID_No, Options, PollQuestion, TotalVotes, DateCreated (automatically populated), CreatedBy, NumberOfAnswers, Answer1, Answer2 ... (as many specified by MaxSelections property) ..., AnswerVotes1, AnswerVotes2 (same number as answer fields), Password.
The Options field must have this form: MultipleVotes Boolean,OnlyUsers Boolean,Category. Example: False,True,'Administrators Poll'
The database, as the polls txt file, must be able to be write-accessed by ASP.NET. You can achieve this by doing the following for a file: Right-click, properties, security, add..., choose aspnet from list, click add, click ok, check the read and write checkboxes and click apply.
Password
The control by itself doesn't have to do anything with each poll's password. It's optional to fill the field. The external .aspx page though in the Files folder does use of it.
External .aspx page (advanced users)
This page shows how you can use the control and let users have their own poll to manage. You can find the page in the Files Folder. Feel free to explore it. I haven't made that page part of the guide 'cause it needs some work to pull it out of my website. In future versions, i'll present it.
Usage:
You can either use the control through script by referring to TPControls.Poll (according to the install instructions), or either through placing a control instance on an .aspx page like this:
<TP:Poll runat="server" [TableWidth="Width of box String"] [DbConStr="Database Connection String"] [ID2Show=Poll ID integer (id existent in database)]
[MaxSelections=Max Answers Integer] [PercentageTablesMaxWidth=Max results table width Integer] [RandomPoll=Boolean] [DisposeIfAlreadyShown=Boolean]
[PollUsersTxt=Path String]
> </TP:Poll>
The brackets [ ] are used to show the optional. Italics are used to show the text you need to type according to your preferences.
e.g. <TP:Poll runat="server" RandomPoll=True />
Comments:
As I've noted, Microsoft 2000 Pro needs to have installed MDAC v2.6 or later for the control to work. You can download it from Microsoft's website.