I have seen a few people asking the above questions recently. Here I will give you a reference answer, but the specific situation should be handled as some special conditions may be required for the functions implemented in Usercontrol, for example, if it depends on some other classes or resources, you should be careful. When debugging is required, check whether the complexity determines whether to continue or simply write Custom Controls.
A. Generate the DLL file
1. let's first create a new project (if you already have a website, you can open it directly) and create a Web User Control. Here we use the inline code mode, no codebehind file.
2. For future reference convenience, give it a namespace. The source code is similar to the following:
<%@ Control Language="C#" ClassName="MyTest.MyUserCtrl" %><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem></asp:DropDownList><script runat="server"></script>
3. Compile: see:
You will get the dll file in the bin, which is similar to the App_Web_myuserctrl.ascx.cdcab7d2.dll file name. This is what you need. Please note that to ensure that you can easily get the User Control you created, select "Use fixed ...",
B. Call
You can add the dll file in the references of another project to register it in aspx:
<% @ Register TagPrefix = "Uc" Namespace = "MyTest" Assembly = "App_Web_myuserctrl.ascx.cdcab7d2" %>
Use it like other controls:
<Uc: MyUserCtrl ID = "ss" runat = "server"/>
Add source code