Dave Burke - Freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

System.Reflection SetProperty

This is my second post on using reflection.  Here is the first.  I started rewriting a web app which lists items then on selection shows the item summary (along with several item-specific functions) to support other similar item types.  So it was an opportunity to implement a base class in the solution's WebUI project namespace and go from there.  A method I wanted to use in the base class set a property in a control in the web project's .ASPX page.  I've used reflection to get a property in a remote class web control, but never set a property.  Here's how it works for me.

System.Web.UI.Control uc_doclist = Page.FindControl("uc_doclist");
Type ucType = uc_doclist.GetType();
System.Reflection.PropertyInfo prop = ucType.GetProperty("pid");
ucType.InvokeMember ("pid", BindingFlags.Default | BindingFlags.SetProperty,null,
     uc_doclist, new object [] {int.Parse(e.CommandArgument.ToString())});


In my googling I found two reflection sources which were helpful:

 

Comments

Fabrice said:

You could also simply cast you control to a base class which has the property you want to access instead of using reflection.
# November 14, 2003 6:12 AM

Dave Burke said:

That's an excellent point, Fabrice. Thanks. But if I understand correctly, the base class which had the control and its property was the web page, and in this case multiple web pages will use the remote base class which I will only know at runtime (yeah, some duplication at the UI level for simplification, though I should redesign further.) You're right though, the cast to the base web page is definitely cleaner.

# November 14, 2003 9:06 AM

Kathie Deetz said:

I love it when people get together and share ideas. Great website, stick with it!

# January 22, 2013 3:36 PM

Georgiann Colp said:

This web site definitely has all of the information I wanted concerning this subject and didn’t know who to ask.

# January 22, 2013 10:24 PM

Merna Kalich said:

Aw, this was a really good post. Spending some time and actual effort to create a superb article… but what can I say… I put things off a whole lot and don't manage to get nearly anything done.

# January 23, 2013 12:20 AM

Sau Putton said:

There's certainly a great deal to learn about this issue. I like all the points you have made.

# January 23, 2013 2:14 AM

Katharine Birman said:

Oh my goodness! Awesome article dude! Thanks, However I am experiencing difficulties with your RSS. I don’t know the reason why I am unable to join it. Is there anyone else getting similar RSS issues? Anyone who knows the answer can you kindly respond? Thanks!!

# January 23, 2013 5:12 AM

Kayce Minichiello said:

You ought to take part in a contest for one of the most useful blogs on the internet. I most certainly will highly recommend this website!

# January 23, 2013 11:23 AM

Vania Marsack said:

Greetings! Very helpful advice in this particular article! It is the little changes that make the biggest changes. Thanks a lot for sharing!

# January 24, 2013 5:31 PM

Gilberte Heffley said:

Hello, I do believe your web site might be having browser compatibility issues. When I take a look at your web site in Safari, it looks fine however when opening in I.E., it's got some overlapping issues. I just wanted to provide you with a quick heads up! Aside from that, fantastic site!

# January 25, 2013 9:31 AM

Eugena Yamanoha said:

You ought to take part in a contest for one of the most useful websites on the internet. I'm going to highly recommend this site!

# January 25, 2013 10:49 PM

Elvina Tremblay said:

This blog was... how do you say it? Relevant!! Finally I've found something that helped me. Many thanks!

# January 26, 2013 6:54 PM

Sherill Lueckenbach said:

I blog frequently and I really appreciate your content. The article has really peaked my interest. I am going to book mark your site and keep checking for new details about once per week. I subscribed to your Feed as well.

# January 27, 2013 5:35 AM

Nan Pochiba said:

Having read this I believed it was extremely informative. I appreciate you spending some time and energy to put this informative article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worthwhile!

# January 27, 2013 11:02 AM

Lisha Raabe said:

It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks

# January 28, 2013 2:13 AM

Stacee Barro said:

I couldn’t refrain from commenting. Well written!

# January 28, 2013 9:41 AM

Mathilda Lampke said:

You are so cool! I do not think I've truly read a single thing like this before. So great to find somebody with a few genuine thoughts on this topic. Seriously.. thanks for starting this up. This web site is one thing that is needed on the internet, someone with some originality!

# January 28, 2013 7:16 PM

Nikita Liner said:

This blog was... how do you say it? Relevant!! Finally I've found something that helped me. Thanks a lot!

# January 29, 2013 11:10 AM

Lorriane Ruff said:

After I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I get 4 emails with the exact same comment. Is there a way you are able to remove me from that service? Kudos!

# January 29, 2013 7:08 PM

Lavette Huysman said:

Pretty! This was an incredibly wonderful article. Thanks for providing this information.

# January 30, 2013 10:36 AM

Marvis Kaan said:

The very next time I read a blog, Hopefully it won't disappoint me just as much as this particular one. I mean, I know it was my choice to read, nonetheless I genuinely thought you'd have something interesting to talk about. All I hear is a bunch of whining about something that you could possibly fix if you weren't too busy looking for attention.

# January 31, 2013 8:29 AM

Francesca Ricciardelli said:

Next time I read a blog, Hopefully it won't fail me as much as this particular one. I mean, Yes, it was my choice to read through, nonetheless I truly thought you'd have something helpful to talk about. All I hear is a bunch of whining about something you could possibly fix if you were not too busy searching for attention.

# February 2, 2013 7:32 AM

Hui Anthes said:

Greetings! Very useful advice in this particular article! It's the little changes that make the most important changes. Thanks a lot for sharing!

# February 4, 2013 5:01 AM

Daphine Longton said:

I blog frequently and I truly appreciate your content. Your article has really peaked my interest. I'm going to take a note of your blog and keep checking for new details about once per week. I opted in for your Feed too.

# February 4, 2013 1:07 PM

Neoma Nothnagel said:

Nice post. I learn something new and challenging on sites I stumbleupon everyday. It's always interesting to read through articles from other writers and practice a little something from other websites.

# February 4, 2013 9:02 PM

Ernestine Carriaga said:

That is a very good tip especially to those new to the blogosphere. Simple but very precise info… Thanks for sharing this one. A must read post!

# February 5, 2013 1:50 PM

Clarissa Holloway said:

Very good article. I'm dealing with some of these issues as well..

# February 12, 2013 2:17 AM

Evelyn Kadi said:

I really love your site.. Very nice colors & theme. Did you develop this web site yourself? Please reply back as I’m looking to create my own site and would like to know where you got this from or exactly what the theme is named. Thanks!

# February 12, 2013 8:47 PM

Teresia Disalvo said:

I blog frequently and I seriously appreciate your content. This article has really peaked my interest. I will bookmark your website and keep checking for new details about once a week. I opted in for your Feed as well.

# February 18, 2013 6:20 AM

Janelle Eitnier said:

Very good article. I certainly love this website. Keep writing!

# February 21, 2013 12:44 AM

Mario Casillas said:

I seriously love your site.. Excellent colors & theme. Did you build this site yourself? Please reply back as I’m attempting to create my very own site and would love to know where you got this from or what the theme is called. Appreciate it!

# February 21, 2013 9:16 PM

Misha Silfies said:

Pretty! This has been an incredibly wonderful article. Many thanks for supplying these details.

# February 22, 2013 6:15 AM

Caroll Karhoff said:

This is the right webpage for anyone who wishes to understand this topic. You realize so much its almost tough to argue with you (not that I really will need to…HaHa). You certainly put a fresh spin on a subject that has been discussed for ages. Great stuff, just great!

# February 22, 2013 8:28 PM

Marhta Botros said:

Pretty! This was a really wonderful post. Many thanks for supplying this information.

# February 23, 2013 10:20 AM

Carolynn Hoefflin said:

Howdy, I think your web site may be having internet browser compatibility issues. When I look at your web site in Safari, it looks fine however, if opening in I.E., it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, wonderful site!

# February 23, 2013 1:04 PM

Jenine Loukota said:

You need to take part in a contest for one of the greatest sites online. I am going to recommend this site!

# February 25, 2013 3:23 AM

Kallie Smolder said:

Greetings! Very useful advice within this article! It's the little changes which will make the biggest changes. Many thanks for sharing!

# February 25, 2013 11:33 AM

survivalgear said:

Then join us after the Fitzgerald left port, heading from Superior, WI to Detroit, Louisville and Atlanta.  <a href="http://survival-gear.info" title="">camping gear</a> This section is famous for selling a few inches up the tent.

# February 26, 2013 7:21 AM

social bookmarks said:

o5cAMK Major thankies for the blog.

# March 13, 2013 11:00 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)