how to pass parameters when "invoking" a control

Discussion in 'ASP .Net Building Controls' started by v1nce, Feb 24, 2004.

  1. v1nce

    v1nce Guest

    Hi

    I'm looking for the -correct- (if any) way to pass parameters when invoking a control
    some kind o
    loadControl(path_of_control,"param1='1' param2='help me'")

    I really need this because we used a portal in which we can "plug" controls
    I got some "generic controls" and I want to specialize them (no modification of cod
    involved only passing of some parameters

    Until now I do it that wa
    create the generic control "generic.ascx
    create specialized control "specific.ascx
    in VS I drag'n drop generic.ascx onto specific.ascx and modify the "html"

    <%@ Register TagPrefix="uc1" TagName="generic" Src="../generic.ascx" %><uc1:generic id="specific" runat="server" param1="1" param2="elp me"></uc1:generic

    This is really dumb (memory usage,end users can't pass parameters so I need to ad
    controls at hand,recompilation needed everytime I add a control) so I'm looking for a solution

    Can anyone point me to any resources or samples (especially in C#)?

    thanks

    Please excuse my English (I'm French)
     
    v1nce, Feb 24, 2004
    #1
    1. Advertising

  2. v1nce

    TK Guest

    "v1nce" <> wrote in message news:<>...
    > Hi,
    >
    > I'm looking for the -correct- (if any) way to pass parameters when invoking a control.
    > some kind of
    > loadControl(path_of_control,"param1='1' param2='help me'");
    >
    > I really need this because we used a portal in which we can "plug" controls.
    > I got some "generic controls" and I want to specialize them (no modification of code
    > involved only passing of some parameters)
    >
    > Until now I do it that way
    > create the generic control "generic.ascx"
    > create specialized control "specific.ascx"
    > in VS I drag'n drop generic.ascx onto specific.ascx and modify the "html"
    >
    > <%@ Register TagPrefix="uc1" TagName="generic" Src="../generic.ascx" %><uc1:generic id="specific" runat="server" param1="1" param2="elp me"></uc1:generic>
    >
    > This is really dumb (memory usage,end users can't pass parameters so I need to add
    > controls at hand,recompilation needed everytime I add a control) so I'm looking for a solution.
    >
    > Can anyone point me to any resources or samples (especially in C#)?
    >
    > thanks,
    >
    > Please excuse my English (I'm French)


    Not sure if this is the answer you are looking for but I recently used
    the following method of creating user controls programatically and
    passing/retrieving parameters to/from an aspx page.

    http://msdn.microsoft.com/library/d...instantiatingusercontrolsprogrammatically.asp

    Tom
     
    TK, Feb 24, 2004
    #2
    1. Advertising

  3. v1nce

    v1nce Guest

    Thanks Tom, that's exactly what I found from another source
    You don't need to pass parameters when "invoking" the control. You just have to cast the control to the correct type and then you can access the properties

    Control c1 = LoadControl("genericControl.ascx")
    // by casting the control as a genericControl we can access his propertie
    // it's that simple (*
    ((genericControl)c1).param1 = "1";
    Page.Controls.Add(c1); // add the control to the Pag

    (*) It's not that simple for me because I loop over n controls whose type is unknown to me
    So I'll have to use some reflexion (GetType() GetProperty()
    Any good link about reflexion ?
     
    v1nce, Feb 26, 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. Henke
    Replies:
    3
    Views:
    3,571
  2. Ben
    Replies:
    5
    Views:
    28,124
    David Jessee
    May 12, 2004
  3. Replies:
    2
    Views:
    6,591
    Joshua Flanagan
    Feb 28, 2005
  4. keith
    Replies:
    9
    Views:
    2,130
    Graham Underwood
    Aug 8, 2008
  5. Chaduke
    Replies:
    2
    Views:
    202
    Chaduke
    Jul 31, 2003
Loading...

Share This Page