title: Using ButtonField or HyperLinkField to write a cookie in ASP.NET
body: <p>I currently have a DetailsView in ASP.NET that gets data from the database based on an ID passed through a QueryString. What I've been trying to do now is to then use that same ID in a new cookie that is created when a user clicks either a ButtonField or a HyperLinkField.</p>
  
  <p>What I have in the .aspx is this:</p>
  
  <pre><code>&lt;asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ArtID"
      DataSourceID="AccessDataSource1" Height="50px" Width="125px"&gt;
      &lt;Fields&gt;
          &lt;asp:ImageField DataAlternateTextField="Title" DataImageUrlField="FileLocation"&gt;
          &lt;/asp:ImageField&gt;
          &lt;asp:BoundField DataField="ArtID" HeaderText="ArtID" InsertVisible="False" ReadOnly="True"
              SortExpression="ArtID" /&gt;
          &lt;asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /&gt;
          &lt;asp:BoundField DataField="ArtDate" HeaderText="ArtDate" SortExpression="ArtDate" /&gt;
          &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /&gt;
          &lt;asp:BoundField DataField="FileLocation" HeaderText="FileLocation" SortExpression="FileLocation" /&gt;
          &lt;asp:BoundField DataField="Medium" HeaderText="Medium" SortExpression="Medium" /&gt;
          &lt;asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /&gt;
          &lt;asp:BoundField DataField="PageViews" HeaderText="PageViews" SortExpression="PageViews" /&gt;
          &lt;asp:HyperLinkField DataNavigateUrlFields="ArtID" DataNavigateUrlFormatString="Purchase.aspx?ArtID={0}"
              NavigateUrl="Purchase.aspx" Text="Add To Cart" /&gt;
          &lt;asp:ButtonField ButtonType="Button" DataTextField="ArtID" Text="Add to Cart" CommandName="btnAddToCart_Click" /&gt;
      &lt;/Fields&gt;
  &lt;/asp:DetailsView&gt;
  </code></pre>
  
  <p>When using a reguler asp.net button such as:</p>
  
  <pre><code>&lt;asp:Button ID="btnAddArt" runat="server" Text="Add To Cart" /&gt;
  </code></pre>
  
  <p>I would have something like this in the VB:</p>
  
  <pre><code>Protected Sub btnAddArt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddArt.Click
      Dim CartArtID As New HttpCookie("CartArtID")
      CartArtID.Value = ArtID.DataField
      CartArtID.Expires = Date.Today.AddDays(0.5)
      Response.Cookies.Add(CartArtID)
  
      Response.Redirect("Purchase.aspx")
  End Sub
  </code></pre>
  
  <p>However, I can't figure out how I go about applying this to the ButtonField instead since the ButtonField does not allow me to give it an ID.</p>
  
  <p>The ID that I need to add to the cookie is the ArtID in the first BoundField.</p>
  
  <p>Any idea's/advice on how I would go about doing this are greatly appreciated!</p>
  
  <p>Alternatively, if I could do it with the HyperLinkField or with the regular button, that would be just as good, but I'm having trouble using a regular button to access the ID within the DetailsView.</p>
  
  <p>Thanks</p>