Best way to share ASP.NET .ascx controls across different website applications?

后端 未结 10 679
轮回少年
轮回少年 2021-01-04 04:39

Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX controls that you want to share across these 2 applications.

What\'s the best way

10条回答
  •  无人及你
    2021-01-04 05:05

    I managed to do this by sacrificing some of the ease of building the controls in the first place.

    You can create a Control Library project that will generate a control library DLL for you. The drawback is that you have to create the controls with code only. In my last project, this was fine. In more complicated controls, this may be a problem.

    Here's an example:

    ")> _
    Public Class BreadCrumb
        WebControl
    
         _
        Property Text() As String
            '...'
        End Property
    
        Protected Overrides Sub RenderContents(output as HtmlTextWriter)
            output.write(Text)
        End Sub
    
        Private Sub Page_Load(...) Handles MyBase.Load
            ' Setup your breadcrumb and store the HTML output '
            ' in the Text property '
        End Sub
    End Class
    

    Anything you put in that Text property will be rendered.

    Then, any controls you put in here can function just like any other control you use. Just import it into your Toolbox, make your registration reference, then plop it onto the ASP page.

提交回复
热议问题