Set properties of an unknown type in a loaded control

A

AC

I am loading a user control specified by the user using
this.Page.LoadControl([path]). This control will have multiple public
properties. If it has a public property, I need to get the name of it, and
the current value of it so I can present dynamically generated textboxes and
allow the the user to set the values. Then, as implied, I need to be able to
set the values of these properties.

I've tried getting the type of the loaded control, then using the
GetProperties and stepping through the PropertyInfo collection, but I keep
getting errors when I try to set the values. Ideas? Any code samples out
there where someone is doing this?
 
S

Scott Mitchell [MVP]

AC said:
I am loading a user control specified by the user using
this.Page.LoadControl([path]). This control will have multiple public
properties. If it has a public property, I need to get the name of it, and
the current value of it so I can present dynamically generated textboxes and
allow the the user to set the values. Then, as implied, I need to be able to
set the values of these properties.

I've tried getting the type of the loaded control, then using the
GetProperties and stepping through the PropertyInfo collection, but I keep
getting errors when I try to set the values. Ideas? Any code samples out
there where someone is doing this?

Just out of curiosity, what values are you wanting to assign these
dynamic, unknown properties? It seems a little odd that you have a UC
with unknown properties, because then how do you know what values to
assign them?

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
A

AC

Scott-

Thanks for the reply... I'm writing a web part for SharePoint, but the
technology will work in ASP.NET so I asked it to a control specific group
(hoping to reach a broader audience). At any rate, we have numerous user
controls (most of them display data from numerous web services) from a few
internal apps we want to expose as web parts in SharePoint sites.

I know of the SmartPart Jan & Patrick (SP MVPs) built, but we do not want to
use it.

I have gotten this far:
Control _control =
this.Page.LoadControl("~/wpusercontrols/FidelityNewsReleases.ascx");
Type _controlType = _control.GetType();
PropertyInfo _pi = _controlType.GetProperty("PropertyName");
_pi.SetValue(_control, "StringOfValueToSet", null);

The problem is that we need toknow how to get the names of the properties
from the user controls once they are added and set values to them.

-AC

Scott Mitchell said:
AC said:
I am loading a user control specified by the user using
this.Page.LoadControl([path]). This control will have multiple public
properties. If it has a public property, I need to get the name of it, and
the current value of it so I can present dynamically generated textboxes and
allow the the user to set the values. Then, as implied, I need to be able to
set the values of these properties.

I've tried getting the type of the loaded control, then using the
GetProperties and stepping through the PropertyInfo collection, but I keep
getting errors when I try to set the values. Ideas? Any code samples out
there where someone is doing this?

Just out of curiosity, what values are you wanting to assign these
dynamic, unknown properties? It seems a little odd that you have a UC
with unknown properties, because then how do you know what values to
assign them?

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top