title: How can I create a custom web server control for a gridview in asp.net
body: <pre><code>Visual Studio 2008 
  .Net 3.5 
  C#
  </code></pre>
  
  <p>I have a web site that has a lot of pages with grid views.  I want to be able to add an "Export to Excel" button on some of the grid views, so I started looking and found Custom Web Server Controls - see <a href="http://msdn.microsoft.com/en-us/library/yhzc935f.aspx" rel="nofollow noreferrer">this page</a> for an example.</p>
  
  <p>This example of a custom label lets you pass in string parameters as input to the custom control:</p>
  
  <pre><code>&lt;aspSample:WelcomeLabel ID="WelcomeLabel1" 
     runat="server" Text="Welcome" DefaultUserName="Guest"&gt;
  &lt;/aspSample:WelcomeLabel&gt;
  </code></pre>
  
  <p>I am not exactly sure how to get started. I am thinking that I create a custom Button control, where the id of the grid view can be passed in as a parameter - I'm just not sure how to do that, if it is even possible.</p>
  
  <p>I don't think I need to create a custom grid view control...  Or, maybe I am making it too complex by looking at custom controls?</p>
  
  <p><strong><em>Please note:</em></strong> I have the code written to be able to export a grid view to an Excel file and it works fine.  I need help on how to make that code more generic, so I can drop it in my ASP by a grid view and let the grid view be "exportable".</p>
  
  <p>Thanks in advance for pointing me in the right direction!</p>