Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Can we develop webparts using VB2005.?? (i tried in C# )

  Asked By: Amos    Date: Dec 24    Category: Sharepoint    Views: 1120

Can i develop webparts using VB2005 ? I installed VS2005 and started
developing my first webpart using C# (2005) and everything is fine.But
in C# i am stuck with a few things like cannot see the form designer

But i still want to give a try using VB2005.Is it possible?Because the
extensions which i installed shows only the web part project template
for C# and doesn't show for VB.Do i need to install anything else.

Any links will really be helpfull.thank you.



3 Answers Found

Answer #1    Answered By: Himanshu Gohil     Answered On: Dec 24

Yes you can create webparts  using VB2005. Since webparts inherit from
ASP.NET server controls you won't see a form designer. The Visual
Studio Extensions for WSS are only available for C#. I'm not sure why
Microsoft didn't create a them for VB.NET also, but they didn't. Having
said that I don't recommend that you use the VSeWSS extensions anyway.
They make too many assumptions and have too many constraints when
creating webparts. Instead you can start with a ClassLibrary and add
references and the proper inheritance to create a webpart.

The following link is one walkthrough. Follow the instructions for a
WebControl Library project.


Answer #2    Answered By: Ashton Schroeder     Answered On: Dec 24

I use Visual Studio 2005 for all my development in C#. The thing about
SharePoint webpart  development is that you won't see the design while you build,
only on deployment. You can build using Visual Basic as well, but I assume to
the same effect.

I think that is one of the hardest things about the WebPart development for me
is imagining the design while I code and "hoping" that it works fine. I usually
have to tweak once I get it to build.

I am not sure which webpart project templates you installed, but you can always
go online and use something like
labs.developerfusion.co.uk/.../csharp-to-vb.aspx to change the code
from C# to VB.

Answer #3    Answered By: Iris Ballard     Answered On: Dec 24

To see a form designer you'll need to put host a User Control. Here are
the steps that I teach for adding a User Control as the front end for
your Web Part:

1. Create a Web Part called something like FullPart with a public
property called something like TextProp

2. Add a TEMPLATE folder to the Web Part project



5. Add a Class file called something like Todd.ascx.cs in the Custom

6. Remove TEMPLATE.CONTROLTEMPLATES.Custom from the namespace, add
"public partial" in front of the keyword class, and derive the class
from System.Web.UI.UserControl

7. Add a Text file called something like Todd.ascx to the Custom folder

8. Type a Control directive at the top of the Text file as follows:

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="Todd.ascx.cs" Inherits="[Namespace].Todd" %>

9. Replace [Namespace] with the actual Namespace from the top of the
Todd.ascx.cs file

10. Save and close the files so that VS.NET editor will detect that this
is now a User Control rather than just a Text file

11. Compile the VS.NET project so that VS.NET Design mode can find the

12. Reopen the Todd.ascx User Control

13. Click on the Design tab at the bottom of the editor window to switch
to Design mode

14. Add a Button and a Label from the Toolbox (if you don't see these
controls, you will need to install the VS.NET Visual Web Developer

15. Double click on the Button to wire up an event

16. Type the following code into the Button1_Click handler (assumes the
names given above):

FullPart thisPart = this.Parent as FullPart;

Label Label1 = this.FindControl("Label1") as Label;

Label1.Text = thisPart.TextProp.ToString();

17. The Label will need to be fully qualified or you must add a using
System.Web.UI.WebControls directive to the top of the class

18. To consume the Todd.ascx User Control, override CreateChildControls
in the FullPart Web Part class and add the following code:

UserControl uc =

Page.LoadControl("_controltemplates/Custom/Todd.ascx") as


19. Compile the project and deploy the bits

20. Add the Web Part to a page and click the Button. The page should
refresh and display the value of the property in the label. Change the
value of the property using the WSS Property Pane and click the Button
again. The new value will be displayed.

While this example is in C#, it would work just as well in VB.NET. Not
only do you get a form designer, since each component has a type-safe
reference to the other, the User Control can use the public
properties/methods of its Web Part host and the Web Part can manipulate
the public properties/methods of its hosted UI. Very powerful and far
more supportable.

Didn't find what you were looking for? Find more on Can we develop webparts using VB2005.?? (i tried in C# ) Or get search suggestion and latest updates.