Click here to Skip to main content
15,891,951 members
Articles / Web Development / HTML

Dynamic Loading of ASP.NET User Controls

Rate me:
Please Sign up or sign in to vote.
3.87/5 (35 votes)
4 Jun 2010CPOL3 min read 369.4K   9.8K   63  
Demonstrates how to dynamically add User Controls to pages at runtime using the LoadControl method

Partial Class usercontrol_SimpleControl
    Inherits System.Web.UI.UserControl

    'Create Delegate to Handle Click event in Default page
    Public Delegate Sub btnDelPost_Click(ByVal sender As Object, ByVal e As System.EventArgs)

#Region "Public Event"

    Public Event btnPostClk As btnDelPost_Click

#End Region

#Region "Public Properties"

    Public Property FirstName() As TextBox
        Get
            Return txtFirstName
        End Get
        Protected Set(ByVal value As TextBox)
            txtFirstName = value
        End Set
    End Property

    Public Property LastName() As TextBox
        Get
            Return txtLastName
        End Get
        Protected Set(ByVal value As TextBox)
            txtLastName = value
        End Set
    End Property

#End Region

    Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPost.Click
        RaiseEvent btnPostClk(sender, e)
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions