Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2008, 02:20 AM
ctt ctt is offline
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ctt
Default CompositeControl - error w/ AssociatedControlID

Hey guys. I've tried every variation in every location of this code I can think of. Basically, I have a composite control that has two panels. In the first Panel, FieldContainer, there is a TextBox Control with ID="InputField". In the second Panel, LabelContainer, there is a Label Control with ID="InputField_Label". When I try to set the Label.AssociatedControlID = TextBox.ID, it doesn't work. Please help. All the relevant code is below. I cut out all the other stuff to make it exclusive to this issue. Thanks a lot

'================================================= ==============
' Default.aspx
'================================================= ==============
<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/AdminTemplate.master" Theme="AdminDefault" Title="Virtual Food Court" CodeFile="Default.aspx.vb" Inherits="CTT.VFC.UI.Pages._Default" %>
<%@ Register Namespace="CTT.VFC.UI.Components" TagPrefix="comp" %>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
    <table>
    <comp:InputRow2 runat="server" ID="testrow" />
    </table>
</asp:Content>
'================================================= ==============
' InputRow2.vb
'================================================= ==============
Namespace CTT.VFC.UI.Components
    Public Class InputRow2
        Inherits CompositeControl
#Region "Child Control Declarations"
        'Controls
        Private ctrlField 'This is set as a textbox on default later, but it could be something else potentially
        Private ctrlLabel As Label
        'Containers
        Private FieldContainer As InputRowContainer
        Private LabelContainer As InputRowContainer
#End Region
#Region "Display Properties"
        Private m_cssClassArray As Array = GetCssClasses(0)
        Protected Property CssClasses() As Array
            Get
                Return m_cssClassArray
            End Get
            Set(ByVal value As Array)
                m_cssClassArray = m_cssClassArray
            End Set
        End Property

        Private m_labelCellWidth
        Protected Property LabelCellWidth() As Integer
            Get
                Return m_labelCellWidth
            End Get
            Set(ByVal value As Integer)
                m_labelCellWidth = value
            End Set
        End Property

        Private m_fieldCellWidth
        Protected Property FieldCellWidth() As Integer
            Get
                Return m_fieldCellWidth
            End Get
            Set(ByVal value As Integer)
                m_fieldCellWidth = value
            End Set
        End Property

        Protected Function GetCssClasses(ByVal intIndex As Integer) As Array
            Dim aryReturn(6) As String
            'Build Basic at Index:0
            Select Case intIndex
                Case 0
                    'MainContent
                    aryReturn(0) = "clsFormRowTable"
                    aryReturn(1) = "clsFieldLabelCell"
                    aryReturn(2) = "clsFieldLabelSubText"
                    aryReturn(3) = "clsInputFieldCell"
                    aryReturn(4) = "clsInputField"
                    aryReturn(5) = "clsFormBreakRow"
                    aryReturn(6) = "clsInputFieldHighlight"
                Case 1
                    'Log-In
                    aryReturn(0) = "clsFormRowTableLogin"
                    aryReturn(1) = "clsFieldLabelCellLogin"
                    aryReturn(2) = "clsFieldLabelSubTextLogin"
                    aryReturn(3) = "clsInputFieldCellLogin"
                    aryReturn(4) = "clsInputFieldLogin"
                    aryReturn(5) = "clsFormBreakRowLogin"
                    aryReturn(6) = "clsInputFieldHighlightLogin"
            End Select
            Return aryReturn
        End Function

#End Region
#Region "Properties"
        Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
            Get
                Return HtmlTextWriterTag.Tr
            End Get
        End Property
#End Region
#Region "Subroutines & Functions"
        Public Overrides ReadOnly Property Controls() As System.Web.UI.ControlCollection
            Get
                Me.EnsureChildControls()
                Return MyBase.Controls
            End Get
        End Property

        Protected Overrides Sub CreateChildControls()
            Me.Controls.Clear()
            FieldContainer = New InputRowContainer(InputRowContainerType.FieldDiv)
            FieldContainer.ID = "FieldContainer"
            CreateContainerChildControls(FieldContainer)
            Me.AddContainer(FieldContainer)
            LabelContainer = New InputRowContainer(InputRowContainerType.LabelDiv)
            LabelContainer.ID = "LabelContainer"
            CreateContainerChildControls(LabelContainer)
            Me.AddContainer(LabelContainer)

            'HOW DO I DO THIS???? -----------------------
            ctrlLabel.AssociatedControlID = ctrlField.ID
            '--------------------------------------------

            ChildControlsCreated = True
        End Sub

        Protected Overridable Sub CreateContainerChildControls(ByVal container As InputRowContainer)
            Select Case container.ContainerType
                Case InputRowContainerType.FieldDiv
                    ctrlField = New TextBox
                    With ctrlField
                        .ID = "InputField"
                        .Text = ctrlField.ClientID '"Default Value"
                        .TextMode = TextBoxMode.SingleLine
                        .Rows = 1
                        .CssClass = CssClasses(4)
                        .Style.Add("display", "inline")
                        .Attributes.Add("OnFocus", "this.className='" & CssClasses(6) & "';")
                        .Attributes.Add("OnBlur", "this.className='" & CssClasses(4) & "';")
                    End With
                    container.Controls.Add(ctrlField)
                    Exit Select
                Case InputRowContainerType.LabelDiv
                    ctrlLabel = New Label
                    With ctrlLabel
                        .ID = "InputField_Label"
                        'I commented it out here, cuz it doesn't work there either, and some of the stuff I found online told me to put it after both controls had been added.
                        '.AssociatedControlID = ctrlField.ID
                        .Text() = "Label Text"
                        .Style.Add("display", "inline")
                    End With
                    container.Controls.Add(ctrlLabel)
                    Exit Select
            End Select
        End Sub

        Protected Overridable Sub AddContainer(ByVal container As InputRowContainer)
            Controls.Add(container)
        End Sub

        Protected Overridable Function CreateContainer(ByVal containerType As InputRowContainerType) As InputRowContainer
            Return New InputRowContainer(containerType)
        End Function

        Protected Overridable Sub RenderContainer(ByVal container As InputRowContainer, ByVal writer As HtmlTextWriter)
            container.RenderControl(writer)
        End Sub

        Protected Overridable Sub RenderSpacerTableCell(ByVal width As Integer, ByVal writer As HtmlTextWriter)
            writer.AddAttribute("width", width.ToString)
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            writer.Write(" ")
            writer.RenderEndTag()
        End Sub

        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
            writer.AddAttribute("class", CssClasses(1))
            writer.AddAttribute("width", Me.LabelCellWidth.ToString)
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            RenderContainer(LabelContainer, writer)
            writer.RenderEndTag()
            RenderSpacerTableCell(5, writer)
            writer.AddAttribute("class", CssClasses(3))
            writer.AddAttribute("width", Me.FieldCellWidth.ToString)
            writer.RenderBeginTag(HtmlTextWriterTag.Td)
            RenderContainer(FieldContainer, writer)
            writer.RenderEndTag()
            RenderSpacerTableCell(5, writer)
        End Sub
#End Region
    End Class
End Namespace
'================================================= ==============
' InputRowContainer.vb
'================================================= ==============
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.VisualBasic

Namespace CTT.VFC.UI.Components
    ''' <summary>
    ''' Summary description for CreditCardFormContainer
    ''' </summary>
    Public Class InputRowContainer
        Inherits Panel
        Implements INamingContainer
        Private m_containerType As InputRowContainerType

        Public Sub New(ByVal containerType As InputRowContainerType)
            Me.m_containerType = containerType
        End Sub

        Public ReadOnly Property ContainerType() As InputRowContainerType
            Get
                Return m_containerType
            End Get
        End Property
    End Class
End Namespace
'================================================= ==============
' InputRowContainerType.vb
'================================================= ==============Imports Microsoft.VisualBasic

Namespace CTT.VFC.UI.Components
    Public Enum InputRowContainerType
        FieldDiv = 1
        ValidationDiv = 2
        LabelDiv = 3
        SubLabelDiv = 4
    End Enum
End Namespace



- Michael Levkoff -
 
Old May 12th, 2008, 07:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

It would help if you'd posted the actual error message. Although you did the right thing by posting the relevant code, you're not really explaining the problem. "it doesn't work" is not enough to dig into this code and see what the problem is.

Please post the actual error message and I'll have another look.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old May 12th, 2008, 10:32 AM
ctt ctt is offline
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ctt
Default

Thanks for reading. The error message is:

System.Web.HttpException: Unable to find control with id 'InputField' that is associated with the Label 'InputField_Label'.

- Michael Levkoff -
 
Old May 12th, 2008, 11:16 AM
ctt ctt is offline
Registered User
 
Join Date: Jul 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ctt
Default

Random Sidenote: I own a copy of Instant Results. Are you on the left, middle or right?

- Michael Levkoff -
 
Old May 13th, 2008, 02:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I haven't been able to run this code, so it's quite difficult for me to say what is going wrong. However, there are things you can take a look at in the hopes you can figure it out.

Take a look at this:

ctrlLabel.AssociatedControlID = ctrlField.ID

Set a breakpoint on this code and then diagnose your control. Have the controls been created successfully?

My guess is that you're setting the AssociatedControlID property too early; before the associated control has been created.

P.S. No need to send me follow up messages through my profile page (I already asked that on that profile page). I respond here if and when I have the time. Reminder messages don't speed up the process in any way....

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old May 13th, 2008, 02:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

P.S. I am the one on the left. I have been using that picture for some time now (again here: http://imar.spaanjaars.com/AboutMyBo...inningaspnet35) but it's getting a bit old (that is, I am....) ;)

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.