Convert the self-created UserControl to a DLL file for other website projects. The source code is provided.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.