object component

J

Jim McGivney

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\wwwroot\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
 
E

Eric

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\wwwroot\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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top