i have written an asp.net user control in vb.net. now i have a c# web application that i need to use this control in, is there some way to export this user control into a dll or something to be able to resuse it
2 Answers
You better move your shared controls to vb.net web application project, then you can reuse that in both vb.net projects and c# projects
Steps:
- create vb.net project with shared user controls. You can create Folder called Controls and put all the user controls there.
- add above shared project to your c# project and create pre buld event to copy ascx files to c# project like below
copy "$(SolutionDir)SharedControl\*.ascx" "$(ProjectDir)Controls\" - you need to add reference to shared control project
- register the controls and use it
ASPX
<%@ Register Src="~/Controls/WebUserControl1.ascx" TagPrefix="uc1" TagName="WebUserControl1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:WebUserControl1 runat="server" ID="WebUserControl1" />
3 Comments
afzalulh
+1 @Damith - We have used this approach and liked it. Easier to look at the control's code and to modify to meet new requirements.
Sisyphus
i have tried that before i made this post, but unfortunately it is not working. i have a solution, with 2 asp.net web applications, one in c# and the other one in vb.net, i created a user control in the vb.net project, then draged and dropped it on a webpage in the c# project. and i got this error postimg.org/image/renrxhv9f , please tell me what i am doing wrong? thank you
Damith
you need to copy ascx files to your project