Q:

sharepoint how to add code handler for button click

I have a SharePoint publishing page. I added a server button via SPD, assign the OnClick handler to btnSubscribe_Click. The question is, how and where can I add codes for this handler? If I have it inside a dll, how can I relate the SharePoint page to the .cs file?

A:

You cannot add controls to publishing pages with SPD, I assume you mean you have added the button to the page layout? or master page?
To make an onclick work, as you know, you need to have a code behind, or script in code. 
1) To make the code behind work, you need to make a custom page layout class, extend from Microsoft.SharePoint.Publishing.PublishingLayoutPage
Then change your page layout declaration to use your new page layout code:
<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

2) Or you can enable inline script through web.config, and have standard <script runat=server> sections
3) Or better yet, write a web part or a control that will do your subscribe action. And add that to your page layout.

