Loadcontrol with parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Wright

    #1

    Loadcontrol with parameters

    Hi

    I'm having this major issue loading a usercontrol at runtime using the
    overload on Loadcontrol(typ e,object). Here's the code in the aspx
    code-behind file

    Dim myControl As New Control
    Dim strCtlPath As String = "~/includes/pinned/NewConsumerRevi ews.ascx"
    Dim objParams(0) As Object
    objParams(0) = 1
    myControl = LoadControl(str CtlPath)
    PlaceHolder1.Co ntrols.Add(Load Control(myContr ol.GetType, objParams))

    and the user control constructors look like this:

    Partial Class Includes_Pinned _NewConsumerRev iews
    Inherits System.Web.UI.U serControl
    Sub New()
    MyBase.New()
    End Sub
    Sub New(ByVal x As Integer)
    MyBase.New()
    End Sub
    <FUNCTIONS>
    End Class
    The error i'm getting is:

    Server Error in '/www.compare-online.co.uk' Application.


    Constructor on type 'ASP.includes_p inned_newconsum erreviews_ascx' not found.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.MissingM ethodException: Constructor on type
    'ASP.includes_p inned_newconsum erreviews_ascx' not found.

    Source Error:

    Line 69:
    Line 70: myControl = LoadControl(str CtlPath)
    Line 71: PlaceHolder1.Co ntrols.Add(Load Control(myContr ol.GetType,
    objParams))
    Line 72:
    Line 73:


    Source File: C:\Solutions\Co mpare
    Online\CompareO nline.Web\compa re-online.co.uk\Ma sterPages\1\Bas e.master.vb
    Line: 71

    Stack Trace:

    [MissingMethodEx ception: Constructor on type
    'ASP.includes_p inned_newconsum erreviews_ascx' not found.]
    System.RuntimeT ype.CreateInsta nceImpl(Binding Flags bindingAttr, Binder
    binder, Object[] args, CultureInfo culture, Object[] activationAttri butes)
    +1036
    System.Activato r.CreateInstanc e(Type type, BindingFlags bindingAttr,
    Binder binder, Object[] args, CultureInfo culture, Object[]
    activationAttri butes) +114
    System.Web.UI.T emplateControl. LoadControl(IWe bObjectFactory
    objectFactory, VirtualPath virtualPath, Type t, Object[] parameters) +329
    System.Web.UI.T emplateControl. LoadControl(Typ e t, Object[] parameters)
    +13
    MasterPages_1_B ase.SetPinnedCo ntent() in C:\Solutions\Co mpare
    Online\CompareO nline.Web\compa re-online.co.uk\Ma sterPages\1\Bas e.master.vb:71
    MasterPages_1_B ase.Page_Load(O bject sender, EventArgs e) in
    C:\Solutions\Co mpare
    Online\CompareO nline.Web\compa re-online.co.uk\Ma sterPages\1\Bas e.master.vb:20
    System.Web.UI.C ontrol.OnLoad(E ventArgs e) +99
    System.Web.UI.C ontrol.LoadRecu rsive() +47
    System.Web.UI.C ontrol.LoadRecu rsive() +131
    System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1061







    Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET
    Version:2.0.507 27.42
    Thanks for any help
    Carl


Working...