Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / October 2006

Tip: Looking for answers? Try searching our database.

Control Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 10 Oct 2006 23:25 GMT
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
Michael Hamrah - 10 Oct 2006 23:43 GMT
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

> Hi,
>
[quoted text clipped - 142 lines]
>
> End Namespace

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.