简体   繁体   中英

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

用c#创建一个新的asp.net用户控件库项目,向该项目添加C#用户控件,然后在您的Visual Basic项目中添加对该库的引用,就是这样;)

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM