Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Control Problem

    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

    shapper Guest

  2. Similar Questions and Discussions

    1. user control problem access value from user control to a page
      Thanks a lot for paying attention to my problem , i tell u the problem i have a main form in which i gave a login label that points to a...
    2. Odd web control problem. Two instances of control A on different pages display each other's data!
      I am currently using the ScottWatter (or ScottWater) Amazon Book Control in a website I am developing. Basically this is the outline: - It is a...
    3. Control derived from datagrid, problem with adding other control and databinding (VB)
      I all, my employer required me to add a bunch of control to a datagrid (such as a drop down list on top corner to select page size and prev, bunch...
    4. Problem with Date & Time Picker control in a Tab Control form
      I'm using the DTPicker (Date and Time Picker) ActiveX control within an ACC2000 Tab Control subform contained within a main form. As I scroll...
    5. Using Table control in a custom composite control. Control does not render properly in design time.
      All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control...
  3. #2

    Default Re: Control Problem

    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" <mdmo...@gmail.com> 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
    Michael Hamrah Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139