Hi anurag,
To create a custom web part visit the site www.datasprings.com/.../...2007CustomWebParts.aspx
Except in the step Deployment of Web Part:
instead of putting the dll into the bin folder as mentioned please make a strong name for the dll in the signing section of the properties of the class library project and simply drag and drop the dll to GAC in the C:\windows\assembly folder follow rest of the steps as mentioned as it is . It is explained with screenshots. I could have detailed the steps but you will understand it better with screen shots and code sample
Also do not forget the safecontrol entry as mentioned in the link in the web.config file of the sharepoint site you are using which is present in C:\Inetpub\wwwroot\wss\VirtualDirectories\{Port number of the webappliction}
Also do not forget to iisreset or selectively refresh the application pool(if iisreset not feasible always check if iis reset may affect other critical applications)
For webparts with user controls use the following code inside
protected override void CreateChildControls()
{
userControl = (UserControl)Page.LoadControl(@"/_controltemplates/UserControl.ascx");
this.Controls.Add(userControl);
}
The user control ascx page should contain the directive at the begining of the page
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Interest.ascx.cs" Inherits="System.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" AutoEventWireup="false" compilationMode="Always" %>
(Where System.Web is the DLL name .Please use the dll name tha appears in the assembly folder as it is and the rest of the information will also be found in the assembly folder )
Then copy paste the user control to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES folder
Always do iisreset after loading dll to GAC
populate the web part in the web parts gallery as mentioned in the screenshots of the above site. {There are many sites explaining this method as a matter of fact}
Also I suggest to go For WSS extensions for VS 2008 for working with sharepoint applications The above method is assuming you dont have one. Else it becomes more easy as most of the steps and codes{i.e the code for overide child controls comes written with it} are already done however for usercontrol web parts you might want to add the tag prefix i mentioned and add the user control to the control templates folder
For Debugging webparts simply add the webpart(working\nonworking) to a page created in the sarepoint site. In VS 2008 Go to Debug-Attach to process- Select w3wp.exe process(if many are present select all thats the easy way out or it is also possible to find the w3wp.exe process name you are interested in by using iisapp command on the cmd) Go to the page where you have added even if it shows error press F5 on the page and you will enter the debug mode. Always use a debug point at page.loadcontrol command to check whther the user control is even loading in the first place for user control webparts
I hope this solves most of the problems. I have not discussed how to add webparts as a part of feature but using wss that will get resolved automatically. Also using VS2010 and Sharepoint 2010{Foundation Server or licensed version} this becomes way more simple