Ask a Question related to ASP.NET General, Design and Development.
-
Andreas Klemt #1
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
-
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... -
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... -
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... -
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>... -
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 -
Andreas Klemt #2
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...and> 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,UserControl> 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 ofsnippet> 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 ato> 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 dynamicallythe> PlaceHolder> > 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> > > Control. Next, you tried to grab it from the Controls Collection ofCollection> > > Page. Don't you think you ought to grab it from the Controls> 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
-
Andreas Klemt #3
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...and> 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,UserControl> 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 ofsnippet> 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 ato> 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 dynamicallythe> PlaceHolder> > 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> > > Control. Next, you tried to grab it from the Controls Collection ofCollection> > > Page. Don't you think you ought to grab it from the Controls> 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
-
Unregistered #4
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 ifUnregistered Guest



Reply With Quote

