LoadControl(Type t, object[] parameters) usage

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default LoadControl(Type t, object[] parameters) usage

    has anybody used this type of loading user controls,

    in the user control how will i hadle the passed parameters in the contructor
    and also

    can somebody give a code script for instantiating the object[] parameters

    thanks.
    ASPboy Guest

  2. Similar Questions and Discussions

    1. New default document type with parameters
      Hi, I'm interested in knowing if I can create a template for a new default document type that contains parameters. The value for these...
    2. Passing parameters by reference to a VC COM Object
      I need to change a C++ COM Object so that it will correctly accept parameters by reference from an ASP/VBscript webapplication. I'm working from...
    3. Cannot serialize object of type System.Object[,]. Multidimensional arrays are not supported
      Hi, I get this on server when trying to retun a 2 dim array. I apprecaite that they are not supported as per...
    4. shockwave object and embed parameters
      Hello, I want to bypass the built-in Director html templates for shockwave. I am looking for a complete listing of shockwave parameters and their...
    5. Cannot pass primitive type parameters to ASP.NET web service
      Hi, I have found the solution to my problem. I simply needed to add the SOAPRpcMethod attribute to my web method as follows: <SoapRpcMethod(),...
  3. #2

    Default Re: LoadControl(Type t, object[] parameters) usage

    for eg. if the constructor for the control you want to load looks like this
    :

    public myUserControl (string s, bool b, int i){// constructor code here}


    // as you can see there are 3 arguments for the constructor.
    // One thing to be careful about is that you need to pass the arguments in
    the same order they are
    // listed in your constructor, and the type of the objects in your object
    array should match,
    // so as in the following code.

    object[] myParameters = {"test", true, 3};

    myUserControl c1 = LoadControl(myUserControl, myParameters);


    Regards,
    Alessandro Zifiglio
    [url]http://www.AsyncUI.net[/url]

    "ASPboy" <g@gmail.com> ha scritto nel messaggio
    news:BNWdncng1rJZlyvZRVnyvQ@giganews.com...
    > has anybody used this type of loading user controls,
    >
    > in the user control how will i hadle the passed parameters in the
    > contructor
    > and also
    >
    > can somebody give a code script for instantiating the object[] parameters
    >
    > thanks.

    Alessandro Zifiglio Guest

  4. #3

    Default Re: LoadControl(Type t, object[] parameters) usage

    Also, dont forget to check the relevent documentation. Its pretty clear in
    what you need to do :

    [url]http://msdn2.microsoft.com/en-us/library/ewtd66a0.aspx[/url]

    Regards,
    Alessandro Zifiglio
    [url]http://www.AsyncUI.net[/url]


    "Alessandro Zifiglio" <AlessandroZifiglio @ -h-o-t-m-a-i-l-c-o-m> ha scritto
    nel messaggio news:uJpL%23MnpGHA.1548@TK2MSFTNGP04.phx.gbl...
    > for eg. if the constructor for the control you want to load looks like
    > this :
    >
    > public myUserControl (string s, bool b, int i){// constructor code here}
    >
    >
    > // as you can see there are 3 arguments for the constructor.
    > // One thing to be careful about is that you need to pass the arguments in
    > the same order they are
    > // listed in your constructor, and the type of the objects in your object
    > array should match,
    > // so as in the following code.
    >
    > object[] myParameters = {"test", true, 3};
    >
    > myUserControl c1 = LoadControl(myUserControl, myParameters);
    >
    >
    > Regards,
    > Alessandro Zifiglio
    > [url]http://www.AsyncUI.net[/url]
    >
    > "ASPboy" <g@gmail.com> ha scritto nel messaggio
    > news:BNWdncng1rJZlyvZRVnyvQ@giganews.com...
    >> has anybody used this type of loading user controls,
    >>
    >> in the user control how will i hadle the passed parameters in the
    >> contructor
    >> and also
    >>
    >> can somebody give a code script for instantiating the object[] parameters
    >>
    >> thanks.
    >
    >

    Alessandro Zifiglio Guest

  5. #4

    Default Re: LoadControl(Type t, object[] parameters) usage

    ASPBoy,

    I feel your pain. Alessandro - you may want to read the question a bit more carefully before you post a potentially condescending response to someone's question. It's not really clear what ASPBoy needs to do to use the LoadControl overload he's asking about.

    ASPBoy - this is a shortfall by MS w/ a documented cop-out they've added to their MSDN Online help. I also would like to use LoadControl(TYPE) not LoadControl(stringPathToControl) because I also see the value in being able to freely move a User Control from one folder to the next without having to search and replace path references in your code... Unfortunately, as I've just mentioned, MS cops out of resolving this with their typical "by-design" response:

    http://msdn.microsoft.com/en-us/library/ewtd66a0(v=VS.90).aspx

    Make sure you have 3.5 framework selected (they haven't fixed this 4.0 either, but the post only shows up in 3.5). They say this, regarding load by type:

    From MSDN Docs online, re: LoadControl(type, params):

    ----------------------------------------------------------------------------
    Does not instantiate controls defined on ascx page
    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103456

    Description
    A page that loads a user control using the Page.LoadControl(Type, Object[]) does not seem to create its children added in the ascx file.
    Using Page.LoadControl(String) works as expected.


    Comments
    Thank you for submitting this issue. We're investigating and will provide an update on status when we have more information.

    -The Web Platform & Tools Team
    Posted by Microsoft on 8/06/2005 at 11:08 AM
    This is by-design since the type "TestUC" is actually the base type used by the partial class, it does not contain the proper code to instantiate TextBox1 reference, which is actually defined in the derived type. There are two workarounds: 1. Use LoadControl("TestControl.ascx"), for all practical, this behaves identically to LoadControl(type) but it instantiates the derived type, which knows how to instantiate TextBox1. 2. Use a single file page and adds <%@ Reference %> directive to the page to reference the user control, and assign a classname to the ascx page. Then it's safe to use LoadControl(type)

    Thanks for reporting the issue.
    Web Platform and Tools Team.
    Posted by Microsoft on 14/06/2005 at 6:31 PM
    --------------------------------------------------------------------------

    So, quite unfortunately, no work around other than to use the LoadControl(pathToControl) technique, as nobody from MS has bothered to respond to users requesting more clarity on the second "workaround" provided above, which is explained just poorly enough to have you waste a few days trying to figure out what they meant. They'll really have to spell it out with a code sample because I have no idea what they're referring to.

    Anyhow, again, I fully feel your pain, and it took me so long to find out why the call wasn't working I felt I had to share the rotten fruits of my labor... :)

    Happy coding!

    Brian
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139