Fidel
Fidel

Reputation: 7397

add c# user control to existing asp.net vb.net project

I've got an existing asp.net project written in vb.net. Another person has written a user control in c#.

Could you please let me know the steps for adding that C# user control to the vb.net app?

I've tried copying them to the folder and using "Add existing item", however it doesn't compile the code behind at all.

Thanks, Fidel

Upvotes: 1

Views: 4159

Answers (4)

atconway
atconway

Reputation: 21304

Just wanted to add another way to accomplish this, as I was just about to ask a question regarding this topic and figured out the solution.

If you truly need to bring over the raw user control files into a new project, you will find simply adding them via 'Add -> Existing Item...' will make each file come into the solution independently and not structure them properly in Solution Explorer.

The trick is to open up the (2) associated user control code files outside of VS.NET prior to adding to your solution and modify thier namespace to be that of your new project. So if in the old project your namespace was:

MyOldProject.CustomControls

...you will want to rename in the .cs and .Designer.cs to the following:

MyNewProject.CustomControls

Then when you go back into VS.NET add add all of the existing items, they will be in their proper arrangement as follows:

MyControl.cs
-->MyControl.Designer.cs
-->MyControl.resx
-->MyControl

Upvotes: 0

Ando
Ando

Reputation: 11409

You could use this tool to add the control to the VS toolbox.

An example of usage (choose either /vs2005 or /vs2008 depending on your VS version):

TOOLBOX.EXE [/vs2005] [/vs2008] /installdesktop assembly tabname

Upvotes: 1

Matt Dearing
Matt Dearing

Reputation: 9386

The C# control will need to be in a seperate dll. You can then add a reference to this dll in your vb project. Then register the control in the page directive or web.config, like normal.

Upvotes: 0

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

create a new asp.net user control library project with c#, add C# user control to that project, than in your visual basic project add reference to that library and that's it ;)

Upvotes: 2

Related Questions