看下面的例子:
<%@ Page Language="c#" %>
<script Language="c#" runat="server">
  void Page_Load(object source, EventArgs e)
  {
    if (!(IsPostBack))
    {
      MyButton.Text = "Save Cookie";
      MyDropDownList.Items.Add("Blue");
      MyDropDownList.Items.Add("Red");
      MyDropDownList.Items.Add("Gray");
    }
  }
  public void Click(object sender, EventArgs e)
  {
    HttpCookie MyCookie = new HttpCookie("Background");
    MyCookie.Value = MyDropDownList.SelectedItem.Text;
    Response.Cookies.Add(MyCookie);
  }</script><html>
  <body>
    <form id="CookieForm" method="post" runat="server">
      <asp:DropDownList id=MyDropDownList runat="server"/>
      <asp:button id=MyButton runat="server" OnClick="Click"/>
    </form>
  </body>
</html>