views:

6

answers:

0

Hi, the below Default.aspx page(code behind is given below) contains a composite control. If we assign an Id to this composite control,while page rendering it creates multiple "ID" attribute for its child controls like "". Removing obj.ID = "MyCompositeControl" creates a single id for all child controls, but we can't set our own name. Could you please check the below code and let me know how to resolve this?

Partial Class _Default Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim obj As New DynamicControl()
    obj.ID = "MyCompositeControl"
    PlaceHolder1.Controls.Add(obj)
End Sub

End Class

Public Class DynamicControl : Inherits CompositeControl Implements INamingContainer

Private oStringWriter As System.IO.StringWriter
Private oHtmlTextWriter As System.Web.UI.HtmlTextWriter
Private _lastTagField As Boolean = False
Private _ChildControlList As New List(Of Control)
Private _ControlMethodList As New Hashtable

Protected Overrides Sub OnLoad(ByVal e As EventArgs)
    Dim oStringWriter As New System.IO.StringWriter
    Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

    RenderControls(oHtmlTextWriter)
End Sub


''' <summary>
''' To render all the controls in the custom control 
''' </summary>
''' <param name="oHtmlTextWriter"></param>
''' <remarks></remarks>
Protected Overrides Sub Render(ByVal oHtmlTextWriter As HtmlTextWriter)
    AddAttributesToRender(oHtmlTextWriter)
    For Each IndControl As Control In _ChildControlList
        If Not IsNothing(IndControl) Then
            IndControl.RenderControl(oHtmlTextWriter)
        End If
    Next
End Sub


Private Sub RenderFieldControls(ByVal objControl As WebControl, ByVal id As String)
    objControl.ID = id
    'AddProperties(objControl, UIIndControl.UI_Property)
    _ChildControlList.Add(objControl)
    Me.Controls.Add(objControl)

    'If Not IsNothing(UIIndControl.UI_Event) Then
    '    RegisterEvent(objControl, UIIndControl.UI_Event, Me.ID & ApplicationConstants._UNDERSCORE & UIIndControl.ID, UIIndControl.ControlType)
    'End If

End Sub

Private Sub RenderControls(ByVal oHtmlTextWriter As System.Web.UI.HtmlTextWriter)

    Dim objtxt As New TextBox()
    RenderFieldControls(objtxt, "ID1")

    Dim objbutton As New Button()
    RenderFieldControls(objbutton, "btn1")

End Sub
''' <summary>
''' To create the child controls
''' </summary>
''' <remarks></remarks>
Protected Overrides Sub CreateChildControls()
End Sub

End Class