In my search for a SharePoint template I could only find templates for C#. There was 1 project for Visual Basic but build with VS2002. I converted the project and rebuild it again in VS2005 and created some basic functions in it to show how you can use the webpart. I am just starting with SharePoint development after some years of visual basic 6 and .net hobby development so any comments welcome!
The webpart shows an htmlbutton, a text box, some text and a textbox with the value you set in the property of the webpart. When you push the Click me button the function Private Sub btnText_ServerClick is called. It will set the value of the textbox to your username.
When the webpart is created it will start by calling CreateChildControls() and RenderWebPart. In the render function it will write out the html to show on the webpart as well as it sets the value of the property field to the value you defined in your webpart properties.
Download the template or download the project.
To easy test the installation I installed VS2005 on a server together with WSS 3.0. After you build the project you can install the dll in the GAC by running the following command:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\gacutil /i <path to your project>\ bin\Release\webparttemplate.dll
Update 8.9.2007: Okay; there was something I forgot to tell. You need to modify your web.config file to tell ASP .NET that your assembly is safe. By default the web.config file will be located in c:\Inetpub\wwwroot\wss\VirtualDirectories\80. The project contains a safecontrols.txt file, add the first line starting with <safecontrol to the SafeControls section of your existing web.config file. Add the second line (starting with <add assembly=) to the <assemblies> section.
Next run iisreset (Warning This will stop and start the web service, so its down for a few seconds and takes some more seconds after starting to load again)
The coding is shown below. Have fun with it, I hope it's helpful for your webpart development.
My information source Chapter 19: Beginning Web Part Development and Walkthrough: Creating a Basic SharePoint Web Part
Imports System.ComponentModel
Imports System.Web.UI
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.WebPartPages
Imports System.Runtime.InteropServices
Imports System.Web.UI.HtmlControls
Imports System.Xml.Serialization
<ToolboxData("<{0}:WebPartTemplate runat='server'></{0}:WebPartTemplate>"), XmlRoot(namespace:="Fabita"), Guid("C19B01AA-4593-4426-87BE-3B4194521CC2")> Public Class WebPartTemplate
Inherits WebPart
Dim WithEvents btnTest As New HtmlButton
Dim lblDisplay As New HtmlInputText
Dim txtProperty As New HtmlInputText
Private Const _defPropertyText As String = "Your webpart property"
Private defPropertyText As String = _defPropertyText
<Browsable(True), Category("Web Part Template"), DefaultValue(_defPropertyText), WebPartStorage(Storage.Shared), FriendlyName("Your text"), Description("Your description of the friendlyname")> Public Property DisplayPropertyText() As String
Get
Return defPropertyText
End Get
Set(ByVal value As String)
defPropertyText = value
txtProperty.Value = value
End Set
End Property
Private Sub btnText_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.ServerClick
Dim user As SPUser = SPContext.Current.Web.CurrentUser
lblDisplay.Value = "Welcome " & user.Name
End Sub
Protected Overrides Sub CreateChildControls()
btnTest.InnerText = "Click me"
Controls.Add(btnTest)
lblDisplay.Value = ""
Controls.Add(lblDisplay)
txtProperty.Value = ""
Controls.Add(txtProperty)
End Sub
Protected Overrides Sub RenderWebPart(ByVal output As System.Web.UI.HtmlTextWriter)
btnTest.RenderControl(output)
lblDisplay.RenderControl(output)
output.WriteLine("<br>Your property")
txtProperty.Value = defPropertyText
txtProperty.RenderControl(output)
End Sub
End Class
VB WebPart.zip (17,42 kb)
WebPartTemplate Project.zip (432,65 kb)