Sisyphus
Sisyphus

Reputation: 910

using VB.net usercontrol in C# project, in asp.net

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

Upvotes: 1

Views: 1221

Answers (2)

Damith
Damith

Reputation: 63065

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:

  1. create vb.net project with shared user controls. You can create Folder called Controls and put all the user controls there.
  2. 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\"
  3. you need to add reference to shared control project
  4. 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" />

Upvotes: 1

Prashant Lakhlani
Prashant Lakhlani

Reputation: 5806

Publish your vb.net project to some folder. That will generate dll. Drop that dll to your c# project's bin. Drop ascx control to some folder in your c# project. Register tag prefix and you are done.

Upvotes: 0

Related Questions