title: How to use a custom Parameter with SqlDataSource
body: <p>I want to add a <code>GridView</code> control to one of my views that is backed by a <code>SqlDataSource</code>. The <code>SelectCommand</code> query is parametrized on the <code>aspnet_Users.UserId</code> GUID for the currently-logged-in user, so I need a way to pass the user ID as a parameter.</p>
  
  <p>I read <a href="https://stackoverflow.com/q/1574554/196844">How to utilize ASP.NET current user name in SqlParameter without code-behind</a> and decided to create a custom <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.parameter.aspx" rel="nofollow noreferrer"><code>Parameter</code></a> named <code>UserIdParameter</code>:</p>
  
  <pre><code>namespace MyApp.Web
  {
      public class UserIdParameter : Parameter
      {
          public UserIdParameter(string name)
              : base(name)
          {
          }
  
          protected UserIdParameter(UserIdParameter parameter)
              : base(parameter)
          {
          }
  
          protected override Parameter Clone()
          {
              return new UserIdParameter(this);
          }
  
          protected override object Evaluate(HttpContext context, Control control)
          {
              return Membership.GetUser().ProviderUserKey;
          }
      }
  }
  </code></pre>
  
  <p>In the ASPX view I then added:</p>
  
  <pre><code>&lt;%@ Register TagPrefix="my" Namespace="MyApp.Web" %&gt;
  </code></pre>
  
  <p>in a line after the <code>&lt;%@ Page ... %&gt;</code> line as well as:</p>
  
  <pre><code>    &lt;SelectParameters&gt;
          &lt;my:UserIdParameter Name="UserId" /&gt;
      &lt;/SelectParameters&gt;
  </code></pre>
  
  <p>within the <code>asp:SqlDataSource</code> element.</p>
  
  <p>Unfortunately I get a Parser Error ("An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.") with the following highlighted in red:</p>
  
  <pre><code>        &lt;my:UserIdParameter Name="UserId" /&gt;
  </code></pre>
  
  <p>Visual Web Developer 2010 Express is also informing me that "Element 'UserIdParameter' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing."</p>
  
  <p>Do I need to modify <code>Web.config</code> in some way? If not, what do I need to do to be able to use my custom <code>UserIdParameter</code> parameter?</p>