Set properties of an unknown type in a loaded control

Discussion in 'ASP .Net Web Controls' started by AC, Nov 4, 2004.

  1. AC

    AC Guest

    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?
    --
    -AC
    AC, Nov 4, 2004
    #1
    1. Advertising

  2. AC wrote:
    > 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

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], Nov 4, 2004
    #2
    1. Advertising

  3. AC

    AC Guest

    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 [MVP]" wrote:

    > AC wrote:
    > > 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
    >
    > http://www.4GuysFromRolla.com
    >
    > * When you think ASP.NET, think 4GuysFromRolla.com!
    >
    AC, Nov 4, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,306
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Vivek Sharma
    Replies:
    2
    Views:
    722
    Vivek Sharma
    Oct 31, 2005
  3. Noah Roberts
    Replies:
    1
    Views:
    381
    Noah Roberts
    Mar 15, 2010
  4. Vivek Sharma

    Accessing the properties of a dynamically loaded control

    Vivek Sharma, Oct 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    87
    Phillip Williams
    Oct 31, 2005
  5. Vincent Arnoux
    Replies:
    1
    Views:
    231
    Arnaud Bergeron
    Aug 11, 2006
Loading...

Share This Page