none
User control constructor parameters RRS feed

  • Question

  • Is it possible to pass parameters to an ASP.net user control via the constructor?  I was planning to call the control straight from the markup but can't see how to set constructor parameters.  

    What would be the best way to get run time values into a control, session variables? 

    Regards

    Dave

    Wednesday, March 7, 2012 8:08 AM

Answers

  • ASP .NET objects like User Controls need to have a parameterless constructor, otherwise the runtime doesn't know how to instantiate it (because it would be necessary to know the values to be passed to the constructor and their names).

    If you want to set values on a User Control, you must use property, that are assigned after instantiation.

    To get session variables from within a User Control, just use the Session property.


    Marco Minerva [MCPD]
    Blog: http://blogs.ugidotnet.org/marcom
    Twitter: @marcominerva

    Wednesday, March 7, 2012 8:41 AM