Author: 
---------------------------
Rob Howard, rhoward@microsoft.com 2/22/02

Description:
---------------------------
The Vote server control is a sample ASP.NET Server 
Control that allows for administrator controled voting 
of topcis - through an XML file. The control has full 
Visual Studio .NET design time support; However, Visual 
Studio .NET is not a requirement to use the control.

Features:K:\liuyang\BOOK_50ex\EXAMPLES\VoteControl\VoteDesigner.cs
---------------------------
- Visual Studio .NET design time support. Two different 
  design-time views: Question and Results. These design time
  views are controlled through the 'DesignTime' property

- Internally reuses additional controls. The Vote control 
  uses the ProgressBar control - source included with the 
  project - to display the percentage of a vote for a particular
  topic.

- Numerical percentage of votes is displayed by default, however, 
  this can easily be disabled by modifying the source to not include
  the percentageCell.

- Support for allowing multiple votes by the same user or restricting
  to only a single vote. This is controlled through the 
  AllowMultipleVote property. When AllowMultipleVote is set to false
  a cookie is written to the client for each poll participated in. When
  set to true, the cookie is ignored.

- Extensive use of ASP.NET Cache for efficient database queries. Includes
  various code paths that determine if the control is executing in
  design-time or run-time. If the control is in run-time, the ASP.NET
  Cache is used to alleviate database lookups.

- Full control through styles of various font, color, and other 
  stylistic attributes through properties.

- The connection string for connecting to the SQL Server database
  may be stored as part of the control's properties, or a value may be
  set in the poll.xml file that tells the server control to use an
  AppSettings value from the ASP.NET configuration system.

- An XML file is used to control poll question and answers. Questions can
  be added during a live poll. 

Installation:
---------------------------
1. Compile source files and move .dll to an ASP.NET applcation. For
   example: c:\InetPub\wwwroot\bin\

2. Move poll.xml to path within ASP.NET application. For example:
   c:\InetPub\wwwroot\

3. Create a file within the application, e.g. test.aspx. For example:
   c:\InetPut\wwwroot\test.aspx.

Add the following code to the test.aspx file:

<%@ Register TagPrefix="cc1" Namespace="Microsoft" Assembly="Vote" %>
<form id="WebForm1" method="post" runat="server">
  <cc1:Vote id="Vote1" runat="server" Path="Poll.xml" ConnectionString="[dsn]">
    <ButtonStyle Font-Size="0.7em" Font-Names="Verdana,Arial" Font-Bold="True"></ButtonStyle>
    <ItemStyle Font-Size="0.7em" Font-Names="Verdana,Arial"></ItemStyle>
    <QuestionStyle Font-Size="0.7em" Font-Names="Verdana,Arial" Font-Bold="True"></QuestionStyle>
  </cc1:Vote>
</form>

4. Edit Poll.xml:
   - Optional: Set connectionAppSettingKey to a <appSettings ... > 
     key in web.config to centralize DSN. For example, if the appSettings
     key value is connectionString:
     connectionAppSettingKey="connectionString"

   - Choices elemements must be identified with a single character 
     that is unique to the poll. For example:
     <a>Option 1</a>
     <b>Option 2</b>
     ....
     <z>Option n</z>

    - The name attribute identifies the name of the Poll that will be 
       used as a key in SQL Server. For example:
       <Poll name="FavoriteFeature" ... >

5. Execute SQL Script:
    - Open Sql Query Analyzer and execute SQL found in Poll.sql 
      in the desired database. For example, 'Northwind'

*** You're now ready to use the test page you created earlier ***



Sample Poll.xml:
---------------------------
Below is the sample poll.xml included within the .zip file:

  <?xml version="1.0" encoding="utf-8" ?>
  <Poll name="FavoriteFeature" 
      connectionAppSettingKey="connectionString" >
	<Question>What is your favorite ASP.NET Feature?</Question>
	<Choices>
		<a>Server Controls</a>
		<b>Web Services</b>
		<c>Output Caching</c>
		<d>Session State</d>
	</Choices>
  </Poll>


Visual Studio .NET Support:
---------------------------
1. In a Web Application project in design mode

2. Right-click on the toolbox, select 'Customize...', Select 
   '.NET Framework...' tab

3. Browse for the compiled control, e.g. c:\inetpub\wwwroot\bin\Vote.dll
   and press OK.

4. Drag and drop control onto a web application from Visual Studio .NET 
   toolbox.


Special Notes:
---------------------------
1. The Vote control must be in <form runat="server"> tags.

2. To use in design mode the following properties must be 
   set by editing the HTML view of the control:

   - ConnectionString
   - Path

   For example:

   <%@ Register TagPrefix="cc1" Namespace="Microsoft" Assembly="Vote" %>
   <form id="WebForm1" method="post" runat="server">
     <cc1:Vote id="Vote1" runat="server" Path="Poll.xml" ConnectionString="[dsn]">
      <ButtonStyle Font-Size="0.7em" Font-Names="Verdana,Arial" Font-Bold="True"></ButtonStyle>
      <ItemStyle Font-Size="0.7em" Font-Names="Verdana,Arial"></ItemStyle>
      <QuestionStyle Font-Size="0.7em" Font-Names="Verdana,Arial" Font-Bold="True"></QuestionStyle>
     </cc1:Vote>
   </form>

3. When in design mode the path must be a physical path, 
   e.g. c:\test\poll.xml, to the XML file and the Connection string 
   must be entered. No values can be read from a web.config file in 
   design time.

4. code is currently hardcoded for path of c:\test\code\poll.xml - 
   if the Path property is specified, the property value 
   will override the hardcoded value. If a path property is not
   specified, the control will look for c:\test\code\poll.xml.

Enjoy!