Saturday, March 24, 2012

newbie: user control question

Hi all!

Currently I have some asp.net pages that nearly implement the same
functionality - so I would like to combine them into one user control. My
question is: is it possible to pass parameters to the user control's
constructor? I would like to specify a parameter that tells the control what
to do internally (e.g. if param=1 then display textbox else display
dropdownbox). The parameter should be stored in ViewState. I could implement
public properties on the control, but I want the parameters to be set only
once.

Thanks

MarkusUser Control Constructors are not instantiated directly. Instead, you use
LoadControl() to load the UserControl. Therefore, I think going with
properties is your best bet.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Markus" <markus_nospam_stehle@.web.de> wrote in message
news:eZUT9au2DHA.3468@.TK2MSFTNGP11.phx.gbl...
> Hi all!
> Currently I have some asp.net pages that nearly implement the same
> functionality - so I would like to combine them into one user control. My
> question is: is it possible to pass parameters to the user control's
> constructor? I would like to specify a parameter that tells the control
what
> to do internally (e.g. if param=1 then display textbox else display
> dropdownbox). The parameter should be stored in ViewState. I could
implement
> public properties on the control, but I want the parameters to be set only
> once.
>
> Thanks
> Markus

0 comments:

Post a Comment