469,616 Members | 1,599 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

object component

On an aspx page with C# code behind I am trying to programmatically change
the ImageUrl of various ImageButtons in response to the text contained in
corresponding label controls.

The following code works:

PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(this.ImageButton12);

PropertyDescriptor myProperty = properties.Find("ImageUrl", false);

myProperty.SetValue(ImageButton12,@"C:\Inetpub\www root\BB\images\X.BMP")

Now I want to replace all references to "ImageButton12" in the above code
with a member of an array such as "pram[2]" so that I can loop through all
the ImageBoxes easily in code.

Where:

string[] pram = new string[]
{"Label33","Label34","Label35","Label36","Label37" ,"Label38","Label39"};

or

string[] pram = new string[] {"this.Label33","this.Label34","this.Label35","
this.Label36"," this.Label37"," this.label38"," this.Label39"};

or

Object[] pram = new Object[]
{"this.Label33","this.Label34","Label35","Label36" ,"Label37","Label38","Label39"};

Each time a get an "Object reference not set to an instance of an object"
error.

I have even tried changing the array to a component array, but then I get a
"Can't implicitly change type" error.

The data type specified is "object component" I need to build an array of
object components that I can address by index number.

Any insight would be appreciated.

Thanks,

Jim


Dec 3 '05 #1
1 1004
Although I'm more a VB programmer, I think I know the answer:
(correct me if I'm wrong)

in the line :
myProperty.SetValue(ImageButton12,@"C:\Inetpub\www root\BB\images\X.BMP")

ImageButton12 is a object, in this case a button.
What you are trying to do is to replace a button-object with a string.
The setvalue method then does not recognize it as an object and gives an
error.

rg.
Eric


"Jim McGivney" <mc****@no-spam.sbcglobal.net> schreef in bericht
news:u6****************@tk2msftngp13.phx.gbl...
On an aspx page with C# code behind I am trying to programmatically change
the ImageUrl of various ImageButtons in response to the text contained in
corresponding label controls.

The following code works:

PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(this.ImageButton12);

PropertyDescriptor myProperty = properties.Find("ImageUrl", false);

myProperty.SetValue(ImageButton12,@"C:\Inetpub\www root\BB\images\X.BMP")

Now I want to replace all references to "ImageButton12" in the above code
with a member of an array such as "pram[2]" so that I can loop through
all the ImageBoxes easily in code.

Where:

string[] pram = new string[]
{"Label33","Label34","Label35","Label36","Label37" ,"Label38","Label39"};

or

string[] pram = new string[]
{"this.Label33","this.Label34","this.Label35"," this.Label36","
this.Label37"," this.label38"," this.Label39"};

or

Object[] pram = new Object[]
{"this.Label33","this.Label34","Label35","Label36" ,"Label37","Label38","Label39"};

Each time a get an "Object reference not set to an instance of an object"
error.

I have even tried changing the array to a component array, but then I get
a "Can't implicitly change type" error.

The data type specified is "object component" I need to build an array of
object components that I can address by index number.

Any insight would be appreciated.

Thanks,

Jim



Dec 3 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by gulu man | last post: by
3 posts views Thread by Stephen Torri | last post: by
7 posts views Thread by colin | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.