locked
Custom Composite Controls failes RRS feed

  • Question

  • User1715503494 posted

     Hi,

    I'm just starting with building my own controls, so i thought to take a very simple example from a book or online to see what's up with templated custom controls.
    So I assembled some code like this

    Namespace MyControls.Dialogs
        Public Class Modal
            Inherits CompositeControl
    
            Private _modalTitle As String
            Private _canvasTemplate As ITemplate
            Private _modalControl As Control
    
    
            Public Property ModalTitle() As String
                Get
                    Return _modalTitle
                End Get
                Set(ByVal value As String)
                    _modalTitle = value
                End Set
            End Property
    
            <TemplateContainer(GetType(Modal)), _
            PersistenceMode(PersistenceMode.InnerProperty)> _
            Public Property ItemTemplate() As ITemplate
                Get
                    Return Me._canvasTemplate
                End Get
                Set(ByVal value As ITemplate)
                    Me._canvasTemplate = value
                End Set
            End Property
    
            Protected Overrides Sub CreateChildControls()
                ItemTemplate.InstantiateIn(Me)
            End Sub
    
        End Class
    End Namespace


    Then the example told to compile the code and register it in the web.config file to use it or in code behind or inline.
    So I registered the .dll file in the web.config under the page controls section like I was told to do.

    <add tagPrefix="Comp" assembly="MyControls" namespace="MyControls.Dialogs"/>

    So very hopefull i was searching in the html intellisense for my registered control, but found nothing.
    When I hardcode the control tags, I got some message of Dialogs is not a member of System.Web.UI... and that my control is not defined.

    Aspx Code
    <Comp:Modal ID="Modal1" runat="server">
                <ItemTemplate>
                    <asp:Label ID="test" runat="server" Text=""></asp:Label>
                </ItemTemplate>
    </Comp:Modal>


    Could someone please tell me what's up with registering custom templated controls in the web.config and using them in intellisense.
    This is getting me crazy. I followed all the guidelines and still nothing appears in intellisense nor gets any control withing the template rendere with the Modaltitle set.

    Thanks DriesM

    Wednesday, August 19, 2009 4:25 PM

Answers

  • User1715503494 posted

     Hi Allen,
    Nevermind, solved the issue.
    Thanks for your effort.

     

    FYI: On line 29
    Public Property DialogInfo() As String  

  •         Get  
  •             Return Me._dialogInfo   
  •         End Get  
  •         Set(ByVal value As String)   
  •             Me._dialogInfo = value   
  •         End Set  
  •     End Property  

     



    Kind Regards.

  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 25, 2009 2:25 AM

All replies

  • User-2106054853 posted

     Hi,

    Have you added the dll as a reference of the web application project? Could you try this one?

    http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/WebApplication5.rar

    Thursday, August 20, 2009 10:34 PM
  • User1715503494 posted

     Hi Chen,
    Yes I've tried that, the .dll file is automatically compiled to the bin folder of my webproject, I right clicked the bin folder and choose add reference, located the dll file.
    No success. However, in your project VS studio doesn't complain about the the control tags, but I've tried the @ Register tag without the registering in the web.config as well without succes.

    The strange thing is when I copy the code to a usercontrol (.ascx) file all works fine.

    Thanks for your response.

     

    DriesM

    Friday, August 21, 2009 3:12 AM
  • User-2106054853 posted

     Hi,

    Could you provie your non-working project for me to investigate? You can upload the project to http://skydrive.live.com/

    Monday, August 24, 2009 3:36 AM
  • User1715503494 posted

     Hi Allen,

    Thanks for your response.
    Its a bit difficult to upload my project because al the pages are wired with database data.
    You would be doing a lot of commenting before a page would render properly.
    However I've copied my code from a servercontrol to a usercontrol (I know its not a solution) but for now it is because of my deadline.

    In this user control (.ascx) everything renders fine, and I'm getting access to the intellisense in the aspx page aswell as in the code behind.
    There is 1 thing i'm confused about, I have set some public properties in the user control (as you will see later below), when i give values to these properties in the aspx page they are set without a problem, but when I render the control with Me.CreateChildControls() and I set the values from the code behind aspx page , the values are not set at all but return empty strings. But I do see the properties in code behind, assuming I can give a value to them.

     

    This is the code of the usercontrol:

    Partial Class ModalDialog
        Inherits System.Web.UI.UserControl
    
        Private _dialogID As String
        Private _dialogInfo As String
    Private _dialogTitle As String Private _dialogCanvas As ITemplate = Nothing Private _dialogTriggers As ITemplate = Nothing #Region "PROPERTIES" Public Property DialogID() As String Get Return Me._dialogID End Get Set(ByVal value As String) Me._dialogID = value End Set End Property Public Property DialogTitle() As String Get Return Me._dialogTitle End Get Set(ByVal value As String) Me._dialogTitle = value End Set End Property Public Property DialogInfo() As String Get Return Me._dialogInfo End Get Set(ByVal value As String) Me._dialogInfo = value End Set End Property <TemplateContainer(GetType(TemplateControl)), _ PersistenceMode(PersistenceMode.InnerProperty)> _ Public Property DialogCanvas() As ITemplate Get MyBase.EnsureChildControls() Return Me._dialogCanvas End Get Set(ByVal value As ITemplate) Me._dialogCanvas = value End Set End Property <TemplateContainer(GetType(ModalDialog)), _ PersistenceMode(PersistenceMode.InnerProperty)> _ Public Property DialogTriggers() As ITemplate Get Return Me._dialogTriggers End Get Set(ByVal value As ITemplate) Me._dialogTriggers = value End Set End Property #End Region #Region "METHODS" Protected Overrides Sub CreateChildControls() RenderDialog() End Sub Protected Sub RenderDialog() With Me .Controls.Add(New LiteralControl(Me.DialogUI("DialogTag"))) .RenderDialogTitle() .RenderDialogCanvas() .RenderDialogTriggers() .Controls.Add(New LiteralControl(Me.DialogUI("EndTag"))) End With PlaceHolder1.Controls.Add(Me) End Sub Protected Sub RenderDialogTitle() With Me .Controls.Add(New LiteralControl(Me.DialogUI("TitleTag"))) .Controls.Add(New LiteralControl(Me.DialogUI("TitleText"))) .Controls.Add(New LiteralControl(Me.DialogUI("TitleTip"))) .Controls.Add(New LiteralControl(Me.DialogUI("TitleTool"))) .Controls.Add(New LiteralControl(Me.DialogUI("ToolClose"))) .Controls.Add(New LiteralControl(Me.DialogUI("ToolInfo"))) .Controls.Add(New LiteralControl(Me.DialogUI("EndTag"))) .Controls.Add(New LiteralControl(Me.DialogUI("EndTag"))) End With End Sub Protected Sub RenderDialogCanvas() With Me .Controls.Add(New LiteralControl(Me.DialogUI("CanvasTag"))) ._dialogCanvas.InstantiateIn(Me) .Controls.Add(New LiteralControl(Me.DialogUI("EndTag"))) End With End Sub Protected Sub RenderDialogTriggers() With Me .Controls.Add(New LiteralControl(Me.DialogUI("TriggerTag"))) ._dialogTriggers.InstantiateIn(Me) .Controls.Add(New LiteralControl(Me.DialogUI("EndTag"))) End With End Sub Protected Function DialogUI() As Dictionary(Of String, String) Dim dialogTags As New Dictionary(Of String, String) With dialogTags .Add("DialogTag", "<div id=""" & Me._dialogID & """ class=""dialog"">") .Add("TitleTag", "<div id=""title"">") .Add("TitleText", "<span>" & Me._dialogTitle & "</span>") .Add("TitleTip", "<p>" & Me._dialogInfo & "</p>") .Add("TitleTool", "<div id=""tools"">") .Add("ToolInfo", "<div id=""info""></div>") .Add("ToolClose", "<div id=""close""></div>") .Add("CanvasTag", "<div id=""canvas"">") .Add("TriggerTag", "<div id=""triggers"">") .Add("EndTag", "</div>") End With Return dialogTags End Function #End Region End Class

    Can you tell me why my public properties are ignore when I set them from code behind, and why they are not ignored when I set them from within the .aspx page?

    Thanks for your response.
    Kind Regards

    DriesM

    Monday, August 24, 2009 10:13 AM
  • User-2106054853 posted

     Hi,

    I cannot see where you set the Properties in your code. For instance, where do you set DialogInfo?

    Could you provide a project that can reproduce this issue? You can create a simple demo that doesn't interact with database.

    Monday, August 24, 2009 10:28 PM
  • User1715503494 posted

     Hi Allen,
    Nevermind, solved the issue.
    Thanks for your effort.

     

    FYI: On line 29
    Public Property DialogInfo() As String  

  •         Get  
  •             Return Me._dialogInfo   
  •         End Get  
  •         Set(ByVal value As String)   
  •             Me._dialogInfo = value   
  •         End Set  
  •     End Property  

     



    Kind Regards.

  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 25, 2009 2:25 AM