DEV Community

Play Button Pause Button
vblover programmer
vblover programmer

Posted on

Asp .Net: Create a Simple 'Web User Control'

Web User Control:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="NewUserControl.ascx.vb" Inherits="MyProjectsWebApplication.NewUserControl" %> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
Enter fullscreen mode Exit fullscreen mode

Create Property for 'Web User Control':

Public Class NewUserControl Inherits System.Web.UI.UserControl Public Property Caption() As String Get Return Me.Label1.Text End Get Set(ByVal value As String) Me.Label1.Text = value End Set End Property Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub End Class 
Enter fullscreen mode Exit fullscreen mode

Rehister 'Web User Control' at Web-Form:

<%@ Register TagPrefix="UC" TagName="NewUserControl" Src="~/NewUserControl.ascx" %> 
Enter fullscreen mode Exit fullscreen mode

Using 'Web User Cotrol' in 'Web-Form':

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <UC:NewUserControl runat="server" Caption="My First Web User Control" /> </asp:Content> 
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
feded profile image
Federico Norberto Dutto

thanks !!!!