Literal content in User Controls

clemexnunord

New Member
Hi,<BR><BR>I have created a very simple user control that displays one of it's properties within a nicely formated table. <BR><BR>Rather than use a custom property, I'd like to be able to display any HTML between the UserControl tags in the .aspx doc.<BR><BR>ie<BR>Like this:<BR><uc1:TitledTextBox id="TitledTextBox1" runat="server">Hello mum</uc1:TitledTextBox><BR><BR>Rather than this:<BR><uc1:TitledTextBox id="TitledTextBox1" runat="server" contents="Hello Mum"></uc1:TitledTextBox><BR><BR>Any ideas?<BR><BR>Cheers,<BR>Pete<BR>You should be able to do something like this(ShowGreen.vb):<BR><BR><BR><BR>Imports System<BR>Imports System.Web<BR>Imports System.Web.UI<BR><BR>Namespace myControls<BR><BR>Public Class ShowColor: Inherits Control<BR><BR>Public Text As String<BR>Public Color As String<BR><BR>Protected Overrides Sub Render( objTextWriter As HtmlTextWriter )<BR> objTextWriter.AddAttribute( "Color", Color )<BR> objTextWriter.RenderBeginTag( "Font" )<BR> objTextWriter.Write( Text )<BR> objTextWriter.RenderEndTag()<BR>End Sub<BR><BR>End Class<BR><BR>End Namespace<BR><BR>remember to compile it to a dll.<BR><BR>in your aspx file, do this:<BR><BR><%@ Register TagPrefix="myControls" Namespace="myControls"<BR>Assembly="ShowGreen"%><BR><BR><html><BR><head><title>DisplayShowGreen.aspx</title></head><BR><body><BR><BR><myControls:ShowGreen<BR> Runat="Server"><BR> Hello World!<BR></myControls:ShowGreen><BR><BR><BR></body><BR></html><BR>
 
Back
Top