how to pass parameters when "invoking" a control

V

v1nce

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)
 
T

TK

v1nce said:
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
 
V

v1nce

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 ?
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top