在asp.net中的C#项目中使用VB.net usercontrol

时间:2021-10-08 01:40:58

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

我在vb.net上写了一个asp.net用户控件。现在我有一个c#web应用程序,我需要使用此控件,有没有办法将此用户控件导出到一个DLL或其他东西,以便能够重新使用它

2 个解决方案

#1


1  

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

您最好将共享控件移动到vb.net Web应用程序项目,然后您可以在vb.net项目和c#项目中重用它

Steps:

脚步:

  1. create vb.net project with shared user controls. You can create Folder called Controls and put all the user controls there.
  2. 使用共享用户控件创建vb.net项目。您可以创建名为Controls的文件夹,并将所有用户控件放在那里。
  3. 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\"
  4. 将以上共享项目添加到您的c#项目并创建pre buld事件以将ascx文件复制到c#项目,如下面复制“$(SolutionDir)SharedControl \ * .ascx”“$(ProjectDir)Controls \”
  5. you need to add reference to shared control project
  6. 您需要添加对共享控制项目的引用
  7. register the controls and use it
  8. 注册控件并使用它

ASPX

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" />

#2


0  

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.

将您的vb.net项目发布到某个文件夹。这将生成DLL。把那个dll放到你的c#项目的bin中。将ascx控件拖放到c#项目中的某个文件夹中。注册标记前缀,您就完成了。

#1


1  

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

您最好将共享控件移动到vb.net Web应用程序项目,然后您可以在vb.net项目和c#项目中重用它

Steps:

脚步:

  1. create vb.net project with shared user controls. You can create Folder called Controls and put all the user controls there.
  2. 使用共享用户控件创建vb.net项目。您可以创建名为Controls的文件夹,并将所有用户控件放在那里。
  3. 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\"
  4. 将以上共享项目添加到您的c#项目并创建pre buld事件以将ascx文件复制到c#项目,如下面复制“$(SolutionDir)SharedControl \ * .ascx”“$(ProjectDir)Controls \”
  5. you need to add reference to shared control project
  6. 您需要添加对共享控制项目的引用
  7. register the controls and use it
  8. 注册控件并使用它

ASPX

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" />

#2


0  

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.

将您的vb.net项目发布到某个文件夹。这将生成DLL。把那个dll放到你的c#项目的bin中。将ascx控件拖放到c#项目中的某个文件夹中。注册标记前缀,您就完成了。