title: Calling a class from a button on an aspx page
body: <p>My page just seems to refresh. I cannot call the <code>LottoTest()</code> class onclick.</p>
  
  <p><strong>ASPX:</strong></p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Draw.aspx.cs" Inherits="Lotto.Draw" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
      &lt;h1&gt;Welcome to the Lotto draw&lt;/h1&gt;
          &lt;asp:Button ID="button1" runat="server" Text="DRAW" OnClientClick="LottoTest()" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Draw.aspx.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace Lotto
  {
      public partial class Draw : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
  
          public void LottoTest()
          {
              Dictionary&lt;int, int&gt; numbers = new Dictionary&lt;int, int&gt;();
              Random generator = new Random();
              while (numbers.Count &lt; 6)
              {
                  numbers[generator.Next(1, 49)] = 1;
              }
  
              string[] lotto = numbers.Keys.OrderBy(n =&gt; n).Select(s =&gt; s.ToString()).ToArray();
  
              foreach (String _str in lotto)
              {
                  Response.Write(_str);
                  Response.Write("&lt;br/&gt;");
              }
          }
      }
  }
  </code></pre>