473,408 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problem setting a property of a user control

Hi, I'm trying to set a property of a user control that is part of another
user control. So I have a control A which contains control B, and I'm trying
to set a property in B from within the codebehind file for A.

In control codebehind for A in page_load :
Protected objButtons As ProductButtons

objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons)
objButtons.ProductID = 8

In the ascx file for Control A
<PRODUCTBUTTONSCTRL:PRODUCTBUTTONS id="ProductButtons1" runat="server"
instance="1"/>

Control B has a property called ProductID

When I run the page I get "Object reference not set to an instance of an
object" on the line objButtons.ProductID = 8

Any ideas on how to get around this? can I reference the sub control B from
within the aspx page that holds control A?

klang
Nov 18 '05 #1
3 1053
"Karl Lang" <kl***@NOSPAM.EXAMPLE.COM> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
Hi, I'm trying to set a property of a user control that is part of another
user control. So I have a control A which contains control B, and I'm trying to set a property in B from within the codebehind file for A.

In control codebehind for A in page_load :
Protected objButtons As ProductButtons

objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons)
objButtons.ProductID = 8

In the ascx file for Control A
<PRODUCTBUTTONSCTRL:PRODUCTBUTTONS id="ProductButtons1" runat="server"
instance="1"/>

Control B has a property called ProductID

When I run the page I get "Object reference not set to an instance of an
object" on the line objButtons.ProductID = 8

Any ideas on how to get around this? can I reference the sub control B from within the aspx page that holds control A?


In general, you should have control A expose a property which simply sets or
gets the corresponding property of control B. That is, the property in A
should delegate to B.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
"Karl Lang" <kl***@NOSPAM.EXAMPLE.COM> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
Hi, I'm trying to set a property of a user control that is part of another
user control. So I have a control A which contains control B, and I'm trying to set a property in B from within the codebehind file for A.

In control codebehind for A in page_load :
Protected objButtons As ProductButtons

objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons)
objButtons.ProductID = 8

In the ascx file for Control A
<PRODUCTBUTTONSCTRL:PRODUCTBUTTONS id="ProductButtons1" runat="server"
instance="1"/>

Control B has a property called ProductID

When I run the page I get "Object reference not set to an instance of an
object" on the line objButtons.ProductID = 8

Any ideas on how to get around this? can I reference the sub control B from within the aspx page that holds control A?


In general, you should have control A expose a property which simply sets or
gets the corresponding property of control B. That is, the property in A
should delegate to B.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In general, you should have control A expose a property which simply sets or gets the corresponding property of control B. That is, the property in A
should delegate to B.


Thanks for the pointer John.
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Alphonse Giambrone | last post by:
I have built a simple composite control that consists of a textbox, requiredfieldvalidator and rangevalidator. For properties that are unique to the individual control, I set/get them directly...
10
by: greenb | last post by:
Our asp.net web app uses a .NET component (DLL) in the bin directory to call several stored procedures back to back to perform updates. They don't return any data. Sometimes the total execution...
36
by: AussieRules | last post by:
Hi, I want to use the user color scheme to set the color of my forms. I now I have to use the. System.Drawing.SystemColors, but which color is the color of a form background as used in other...
0
by: David Hearn | last post by:
I have a user control that acts as a header for the parent page that it is sitting on. I was having some errors with it and per another users suggestion in this newsgroup, it cleared up my problem...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
3
by: RSH | last post by:
Hi, I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net page. Each control has its own unique id. When the user selects a value from each of the dropdownlists it is...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
4
by: =?Utf-8?B?QW5keSBXZWVkbWFu?= | last post by:
I have two projects in a solution. Project 1 is a user control. In this user control I define an application setting to store a url the user control needs to talk to. Project 2 is our...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.