Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Control Problem

Reply
Thread Tools

Control Problem

 
 
shapper
Guest
Posts: n/a
 
      10-10-2006
Hi,

I created my first custom control.
I don't get any error when I use it but it doesn't show anything.
Could someone tell me if I am doing something wrong in my custom
control?
I am sure is something simple which I don't know.

Thanks,
Miguel

Here is my custom control code:

' -- [Import Namespaces] -------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

' -- [Namespaces] -------------------------------------------

' Web
Namespace Web

' -- [Classes] -------------------------------------------
<DefaultProperty("Text"), ToolboxData("<{0}:Message
runat=server></{0}:Message>")> _
Public Class Message
Inherits WebControl

' -- [Properties] -------------------------------------------

' ImagePosition
<Bindable(True), Category("Layout"), DefaultValue(""),
Localizable(True)> Property ImagePosition() As String
Get
Dim pImagePosition As String = CStr(ViewState("ImagePosition"))
If pImagePosition Is Nothing Then
Return String.Empty
Else
Return pImagePosition
End If
End Get

Set(ByVal Value As String)
ViewState("ImagePosition") = Value
End Set

End Property

' ImageUrl
<Bindable(True), Category("Appearance"), DefaultValue(""),
Localizable(True)> Property ImageUrl() As String
Get
Dim pImageUrl As String = CStr(ViewState("ImageUrl"))
If pImageUrl Is Nothing Then
Return String.Empty
Else
Return pImageUrl
End If
End Get

Set(ByVal Value As String)
ViewState("ImageUrl") = Value
End Set

End Property

' Text
<Bindable(True), Category("Font"), DefaultValue(""),
Localizable(True)> Property Text() As String
Get
Dim pText As String = CStr(ViewState("Text"))
If pText Is Nothing Then
Return String.Empty
Else
Return pText
End If
End Get

Set(ByVal Value As String)
ViewState("Text") = Value
End Set

End Property

' -- [Functions] -------------------------------------------

' Render contents
Protected Overrides Sub RenderContents(ByVal output As
HtmlTextWriter)

End Sub

' Create Child Controls
Protected Overrides Sub CreateChildControls()

' Create child controls
Dim iIcon As New Image
Dim lText As New Label
Dim pMessage As New Panel
Dim pText As New Panel

' Define iIcon properties
With iIcon
.ImageUrl = Me.ImageUrl
.ID = "iIcon"
.Style.Add("float", "left")
End With

' Define lText properties
With lText
.ID = "lText"
.Text = Me.Text
End With

' Define pMessage properties
With pMessage
.ID = "pMessage"
.Width = Me.Width
End With

' Define pText properties
With pText
.ID = "pText"
.Style.Add("float", "left")
End With

' Add child controls
Me.Controls.Add(pMessage)
pMessage.Controls.Add(iIcon)
pMessage.Controls.Add(pText)
pText.Controls.Add(lText)

' Create child controls
MyBase.CreateChildControls()
Me.ChildControlsCreated = True

End Sub

End Class

End Namespace

 
Reply With Quote
 
 
 
 
Michael Hamrah
Guest
Posts: n/a
 
      10-10-2006
After a quick glance it looks like your RenderContents method is empty:

' Render contents
Protected Overrides Sub RenderContents(ByVal output As
HtmlTextWriter)

End Sub

You shouldn't override this if you're not doing anything, or call
base.RenderContents (that's the c# syntax, not sure about vb).
Internally RenderContents usually calls base.Render which actually does
the writing of HTML.

Michael Hamrah



On Oct 10, 6:25 pm, "shapper" <(E-Mail Removed)> wrote:
> Hi,
>
> I created my first custom control.
> I don't get any error when I use it but it doesn't show anything.
> Could someone tell me if I am doing something wrong in my custom
> control?
> I am sure is something simple which I don't know.
>
> Thanks,
> Miguel
>
> Here is my custom control code:
>
> ' -- [Import Namespaces] -------------------------------------------
> Imports System
> Imports System.Collections.Generic
> Imports System.ComponentModel
> Imports System.Text
> Imports System.Web
> Imports System.Web.UI
> Imports System.Web.UI.WebControls
>
> ' -- [Namespaces] -------------------------------------------
>
> ' Web
> Namespace Web
>
> ' -- [Classes] -------------------------------------------
> <DefaultProperty("Text"), ToolboxData("<{0}:Message
> runat=server></{0}:Message>")> _
> Public Class Message
> Inherits WebControl
>
> ' -- [Properties] -------------------------------------------
>
> ' ImagePosition
> <Bindable(True), Category("Layout"), DefaultValue(""),
> Localizable(True)> Property ImagePosition() As String
> Get
> Dim pImagePosition As String = CStr(ViewState("ImagePosition"))
> If pImagePosition Is Nothing Then
> Return String.Empty
> Else
> Return pImagePosition
> End If
> End Get
>
> Set(ByVal Value As String)
> ViewState("ImagePosition") = Value
> End Set
>
> End Property
>
> ' ImageUrl
> <Bindable(True), Category("Appearance"), DefaultValue(""),
> Localizable(True)> Property ImageUrl() As String
> Get
> Dim pImageUrl As String = CStr(ViewState("ImageUrl"))
> If pImageUrl Is Nothing Then
> Return String.Empty
> Else
> Return pImageUrl
> End If
> End Get
>
> Set(ByVal Value As String)
> ViewState("ImageUrl") = Value
> End Set
>
> End Property
>
> ' Text
> <Bindable(True), Category("Font"), DefaultValue(""),
> Localizable(True)> Property Text() As String
> Get
> Dim pText As String = CStr(ViewState("Text"))
> If pText Is Nothing Then
> Return String.Empty
> Else
> Return pText
> End If
> End Get
>
> Set(ByVal Value As String)
> ViewState("Text") = Value
> End Set
>
> End Property
>
> ' -- [Functions] -------------------------------------------
>
> ' Render contents
> Protected Overrides Sub RenderContents(ByVal output As
> HtmlTextWriter)
>
> End Sub
>
> ' Create Child Controls
> Protected Overrides Sub CreateChildControls()
>
> ' Create child controls
> Dim iIcon As New Image
> Dim lText As New Label
> Dim pMessage As New Panel
> Dim pText As New Panel
>
> ' Define iIcon properties
> With iIcon
> .ImageUrl = Me.ImageUrl
> .ID = "iIcon"
> .Style.Add("float", "left")
> End With
>
> ' Define lText properties
> With lText
> .ID = "lText"
> .Text = Me.Text
> End With
>
> ' Define pMessage properties
> With pMessage
> .ID = "pMessage"
> .Width = Me.Width
> End With
>
> ' Define pText properties
> With pText
> .ID = "pText"
> .Style.Add("float", "left")
> End With
>
> ' Add child controls
> Me.Controls.Add(pMessage)
> pMessage.Controls.Add(iIcon)
> pMessage.Controls.Add(pText)
> pText.Controls.Add(lText)
>
> ' Create child controls
> MyBase.CreateChildControls()
> Me.ChildControlsCreated = True
>
> End Sub
>
> End Class
>
> End Namespace


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control to Control Other User Control Jonathan Wood ASP .Net 4 02-02-2010 03:41 PM
Control, Web Control and Composite Control shapper ASP .Net 6 12-26-2007 02:49 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden ASP .Net 1 10-11-2003 07:09 PM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net 0 07-01-2003 09:26 PM



Advertisments