Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Composite control doesn't work when equals nothing

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
I've created a composite control and it works fine except I don't know the syntax for when a property of the control is nothing.

I have dropped my composite control onto my form, within Visual Studio, 3 times. In the first one I leave the property equal to nothing. I assign values to the property in the 2nd and 3rd copy of the control. When I click on the 2nd or 3rd copy of the control, the property displays correctly. However, if I click on the 1st one, the property displays the value of the 3rd one rather than nothing. I believe it has to do with the line of code below (shown in red).

Since I'm assuming that that line of code is giving me the problem, does anyone know what the correct syntax should be?

Code:
<ToolboxData("<{0}:MHS runat=server></{0}:MHS"), _
Designer(gettype(WBS.Web.UI.Design.MHSDesigner))> _
Public Class MHS

    Inherits  CompositeControl
    Implements IValidator
    Implements ICallbackEventHandler

    Public Shared cnnInfo As New clsConfigureDataSource

    <NotifyParentProperty(True), _
    DefaultValue(""), _
    Description(""), _
    PersistenceMode(PersistenceMode.InnerProperty), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
    DisplayName("(Configure Data Source)"), _
    RefreshProperties(RefreshProperties.Repaint)> _
    Public Property cbox() As clsConfigureDataSource

        Get
            try
If CType(ViewState("cbox"), Object) Is Nothing Then return cnnInfo
Code:
                Return DirectCast(ViewState("cbox"), clsConfigureDataSource)

            catch ex as Exception
                msgbox("(Configure Data Source):" & vbcrlf & ex.Message)
                return cnnInfo
            end try

        End Get


        Set(ByVal Value As clsConfigureDataSource)

            try

                ViewState("cbox") = value
                cnnInfo = value

            catch ex as Exception
                msgbox(i & " " & "(Configure Data Source):" & vbcrlf & ex.Message & vbcrlf & me.id)
            end try

        End Set

    End Property

Code:
<TypeConverter(GetType(clsParentProperty_ConfigureDataSource))> _
Public Class clsConfigureDataSource

    Private strUDLFile as String = ""


    <NotifyParentProperty(True), _
    Description(""), _
    DefaultValue(""), _
    TypeConverter(GetType(clsUDLFiles_LookUp)), _
    DisplayName("1. Data Source"), _
    RefreshProperties(RefreshProperties.All)> _
    Public  Property DataSource() as string
        Get
            Return strUDLFile
        End Get

        Set(ByVal value As string)
            strUDLFile = value
        End Set
    end Property
 
Figured it out (I think...at least it works for now).

The code in red should look like this:

If CType(ViewState("cbox"), Object) Is Nothing Then
Dim cbox1 As New clsConfigureDataSource
return cbox1
End If
 
Although my solution fixed the original problem, it fails when I try to set one of the properties. The code above goes into an infinite loop.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top