URGENT: HowTo reference dynamically to a class name vb.net

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

  1. #1

    Default Re: URGENT: HowTo reference dynamically to a class name vb.net

    Hello Kevin,
    ok thanks, but can you give me an example how to reference dynamically to
    the class to call a method.
    Thanks,
    Andreas

    "Kevin Spencer" <kevin@takempis.com> schrieb im Newsbeitrag
    news:e7hu7sCWDHA.2032@TK2MSFTNGP11.phx.gbl...
    > First, you added your Control to the Controls collection of a PlaceHolder
    > Control. Next, you tried to grab it from the Controls Collection of the
    > Page. Don't you think you ought to grab it from the Controls Collection of
    > the PlaceHolder Control instead?
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > [url]http://www.takempis.com[/url]
    > Complex things are made up of
    > lots of simple things.
    >
    > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
    > news:eFYb0BCWDHA.1204@TK2MSFTNGP12.phx.gbl...
    > > Hello,
    > > I have this
    > >
    > > I loading dynamically WebControls
    > > Dim ctl As Control = Page.LoadControl("Controls/ & userID.ToString &
    > > ".ascx")
    > > ctl.ID = "ctlUser
    > > Me.placeHolder1.Controls.AddAt(0, ctl)
    > >
    > > Now I want to dynamically Reference to the control like this:
    > > CType(Me.FindControl("ctlUser"), ??dynamicallyClassname??)
    > >
    > > How is this possible?
    > >
    > > Thanks in advance,
    > > Andreas
    > >
    > >
    >
    >

    Andreas Klemt Guest

  2. Similar Questions and Discussions

    1. Dynamic Web Reference in Class Lib/GAC
      Hello. I have a shared assembly with a reference to one of our web services. This web reference needs to be dynamic so that we can use different...
    2. How-to reference AS scriptlets or MXML from an AS class?thx
      Hello all: I'm utilizing FlexUnit to test a Flex Application. This Unit testing framework is sorta like JUnit for Java. It requires all test...
    3. HowTo: Dynamically Add Custom Controls?
      Hi There! I'm having trouble dynamically adding custom controls. My custom controls does not use code-behind but only <script /> block for...
    4. Howto reference non-webcontrols on an ASPX page?
      Like the <asp:ListBox> and <asp:ListItem> pair, my control use item definitions, just they are in another assembly: <mycontrollib:myctrl1>...
    5. HowTo get a Viewstate Value from my Parent Class?
      Hello, lets say I want to get from my Parent Class the viewstate("userID") How can I access this an get the value? Thanks for any help Andreas
  3. #2

    Default Re: URGENT: HowTo reference dynamically to a class name vb.net

    Hello Kevin,
    many thanks for you reply.
    I would be happy if you could post an example which could show
    how to load dynamically a type which is in my placeHolder. In my
    class I want to call a function which gives me back a String where some
    form values are in there from a postback.
    And I call always the same Method-Name but I have different UserControls.

    I would be very glad if you could help me!

    Thanks in advance,
    Andreas


    "Kevin Spencer" <kevin@takempis.com> schrieb im Newsbeitrag
    news:u$Y7IsDWDHA.2156@TK2MSFTNGP11.phx.gbl...
    > Hi Andreas,
    >
    > It's kind of difficult to answer your question, as I don't have enough
    > information. In the code you posted, you're loading a UserControl
    > dynamically, and it could be one of many different User Controls. In your
    > code, you can get the ID of the control, as you are assigning it after
    > adding it to the Controls Collection of the PlaceHolder. But of course, in
    > order to call a method of that Control, you need to know the Type of it,
    and
    > cast it as that Type. Finding out the Type isn't difficult, but how you go
    > about it, and how you call a method, depends on a couple of things that
    > aren't apparent from your description so far.
    >
    > For example, as the Controls are all UserControls, if you want to call a
    > method of UserControl, you can just cast the object as
    > System.Web.UI.UserControl, as all the properties and methods of
    UserControl
    > are shared by all UserControls. If, on the other hand, you want to call a
    > method that is specific to the implementation of UserControl which you've
    > created, it gets more difficult, as you won't know what methods are
    > available to that Control initially (it could be any of many inherited
    > Types). In that case, you could use Reflection to find out the type of the
    > Control and then use a Select Case Statement to figure out which method to
    > call, depending on the Type.
    >
    > If you can clarify the missing information, I will be glad to post a
    snippet
    > as an example.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > [url]http://www.takempis.com[/url]
    > Complex things are made up of
    > lots of simple things.
    >
    > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
    > news:e8phzzCWDHA.2228@TK2MSFTNGP12.phx.gbl...
    > > Hello Kevin,
    > > ok thanks, but can you give me an example how to reference dynamically
    to
    > > the class to call a method.
    > > Thanks,
    > > Andreas
    > >
    > > "Kevin Spencer" <kevin@takempis.com> schrieb im Newsbeitrag
    > > news:e7hu7sCWDHA.2032@TK2MSFTNGP11.phx.gbl...
    > > > First, you added your Control to the Controls collection of a
    > PlaceHolder
    > > > Control. Next, you tried to grab it from the Controls Collection of
    the
    > > > Page. Don't you think you ought to grab it from the Controls
    Collection
    > of
    > > > the PlaceHolder Control instead?
    > > >
    > > > --
    > > > HTH,
    > > >
    > > > Kevin Spencer
    > > > Microsoft MVP
    > > > .Net Developer
    > > > [url]http://www.takempis.com[/url]
    > > > Complex things are made up of
    > > > lots of simple things.
    > > >
    > > > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
    > > > news:eFYb0BCWDHA.1204@TK2MSFTNGP12.phx.gbl...
    > > > > Hello,
    > > > > I have this
    > > > >
    > > > > I loading dynamically WebControls
    > > > > Dim ctl As Control = Page.LoadControl("Controls/ & userID.ToString &
    > > > > ".ascx")
    > > > > ctl.ID = "ctlUser
    > > > > Me.placeHolder1.Controls.AddAt(0, ctl)
    > > > >
    > > > > Now I want to dynamically Reference to the control like this:
    > > > > CType(Me.FindControl("ctlUser"), ??dynamicallyClassname??)
    > > > >
    > > > > How is this possible?
    > > > >
    > > > > Thanks in advance,
    > > > > Andreas
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Andreas Klemt Guest

  4. #3

    Default Re: URGENT: HowTo reference dynamically to a class name vb.net

    Kevin, here is what I mean

    Page_Init:
    Select Case userID
    case 1
    Dim ctl As Control = Page.LoadControl("myControls/userID" & userID.ToString
    & ".ascx")
    ctl.ID = "idOfMyUserControl"
    Me.placeHolder1.Controls.AddAt(0, ctl)
    ....
    End Select
    ....
    ....
    After PostBack:

    CType(Me.FindControl("idOfMyUserControl"), "DYNAMIC
    TYPE??").GetValuesAsString





    "Kevin Spencer" <kevin@takempis.com> schrieb im Newsbeitrag
    news:u$Y7IsDWDHA.2156@TK2MSFTNGP11.phx.gbl...
    > Hi Andreas,
    >
    > It's kind of difficult to answer your question, as I don't have enough
    > information. In the code you posted, you're loading a UserControl
    > dynamically, and it could be one of many different User Controls. In your
    > code, you can get the ID of the control, as you are assigning it after
    > adding it to the Controls Collection of the PlaceHolder. But of course, in
    > order to call a method of that Control, you need to know the Type of it,
    and
    > cast it as that Type. Finding out the Type isn't difficult, but how you go
    > about it, and how you call a method, depends on a couple of things that
    > aren't apparent from your description so far.
    >
    > For example, as the Controls are all UserControls, if you want to call a
    > method of UserControl, you can just cast the object as
    > System.Web.UI.UserControl, as all the properties and methods of
    UserControl
    > are shared by all UserControls. If, on the other hand, you want to call a
    > method that is specific to the implementation of UserControl which you've
    > created, it gets more difficult, as you won't know what methods are
    > available to that Control initially (it could be any of many inherited
    > Types). In that case, you could use Reflection to find out the type of the
    > Control and then use a Select Case Statement to figure out which method to
    > call, depending on the Type.
    >
    > If you can clarify the missing information, I will be glad to post a
    snippet
    > as an example.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > [url]http://www.takempis.com[/url]
    > Complex things are made up of
    > lots of simple things.
    >
    > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
    > news:e8phzzCWDHA.2228@TK2MSFTNGP12.phx.gbl...
    > > Hello Kevin,
    > > ok thanks, but can you give me an example how to reference dynamically
    to
    > > the class to call a method.
    > > Thanks,
    > > Andreas
    > >
    > > "Kevin Spencer" <kevin@takempis.com> schrieb im Newsbeitrag
    > > news:e7hu7sCWDHA.2032@TK2MSFTNGP11.phx.gbl...
    > > > First, you added your Control to the Controls collection of a
    > PlaceHolder
    > > > Control. Next, you tried to grab it from the Controls Collection of
    the
    > > > Page. Don't you think you ought to grab it from the Controls
    Collection
    > of
    > > > the PlaceHolder Control instead?
    > > >
    > > > --
    > > > HTH,
    > > >
    > > > Kevin Spencer
    > > > Microsoft MVP
    > > > .Net Developer
    > > > [url]http://www.takempis.com[/url]
    > > > Complex things are made up of
    > > > lots of simple things.
    > > >
    > > > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
    > > > news:eFYb0BCWDHA.1204@TK2MSFTNGP12.phx.gbl...
    > > > > Hello,
    > > > > I have this
    > > > >
    > > > > I loading dynamically WebControls
    > > > > Dim ctl As Control = Page.LoadControl("Controls/ & userID.ToString &
    > > > > ".ascx")
    > > > > ctl.ID = "ctlUser
    > > > > Me.placeHolder1.Controls.AddAt(0, ctl)
    > > > >
    > > > > Now I want to dynamically Reference to the control like this:
    > > > > CType(Me.FindControl("ctlUser"), ??dynamicallyClassname??)
    > > > >
    > > > > How is this possible?
    > > > >
    > > > > Thanks in advance,
    > > > > Andreas
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Andreas Klemt Guest

  5. #4

    Default HowTo reference dynamically to a class name vb.net

    Can you try something like this:

    dim ctrl as control = CType(Me.FindControl("idOfMyUserControl"), object)
    if not isnothing(ctrl) then
    'to do: get the type of the control etc...
    end if
    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