Wrox Programmer Forums
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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 November 28th, 2005, 12:01 PM
Registered User
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing Control Property


I am working on an shopping-type site. I have a page where a product is pulled from a database and displayed. Along with the usual product information, it has a single category ID number which tells the ASPX page (product.aspx) which category it is from. The script then uses this number to display the product's category (e.g. books > fiction > crime)

The page has a dynamic navigation menu at the side. This is built/displayed using a compiled control in a DLL.

The menu is an extension of a standard ASP.NET XML control. The only difference is that it has an additional property - the category id. It is found on the page as:

<shop:xmlMenu runat="server" id="LeftMenu" categoryID="15"/>
The compiled control should take the category ID (which can be hard-wired into the .aspx page or set using the code-behind) and dynamically build an XML menu which is transformed using XSLT. There are various reasons for doing it this way.

The result is that the menu expands and contracts depending on which section you are browsing.

HOWEVER, the compiled control does not seem able to access the public

I know the script works without using a property as I originally planned to use a query string to get the category id. It just doesn't seem to work with a property

The code for the compiled control is:

Public Class XmlMenu

    Inherits System.Web.UI.WebControls.Xml

    Public sCategoryID As Integer = 0   'Default value

    Public Property CategoryID As Integer
              Return sCategoryID
           End Get
           Set(ByVal Value As Integer)
              sCategoryID = value
           End Set
         End Property

    Public Sub New()

        Dim NewXml As New XmlDocument()
        NewXML = BuildMenu(sCategoryID)        
        Me.Document = NewXml
        Me.TransformSource = "menu.xsl"

    End Sub

    Public Function BuildMenu(CatID As Integer) As XmlDocument    
             'Do stuff to generate XML with CatID variable using a database etc.

         BuildMenu = MenuXML

    End Function
End Class

Old November 28th, 2005, 02:48 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

You're calling BuildMenu too early.

Right now, you call this code in the class constructor. At that point, the class is constructed but its properties haven't been set (which makes sense because before the object is constructed, there is no object to set properties on).

Move the BuildMenu code to Page_Load for example, or another appropriate event handler and things will work.


Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: City sickness by Tindersticks (From the album: Donkeys 92-97) What's This?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Property in Custom control watashi Visual C++ 0 October 22nd, 2008 11:20 PM
Accessing SelectMethod Property of SQLDataSource Sheraz Khan ASP.NET 2.0 Professional 0 September 9th, 2007 08:00 AM
accessing property from code behind in .ascx reks_dnet ASP.NET 1.0 and 1.1 Professional 1 May 23rd, 2007 08:35 AM
User Control Name in a Text Property laslanid Pro VB.NET 2002/2003 0 February 24th, 2005 04:31 AM
Accessing the property of the website jyoti_khera General .NET 0 January 28th, 2005 04:17 AM

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