Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Compiled Code accessing New User Controls at runtime

Reply
Thread Tools

Compiled Code accessing New User Controls at runtime

 
 
Earl Teigrob
Guest
Posts: n/a
 
      04-02-2004
I am writing an application that dynamically loads user controls at run time
based on user options. I would like to give my users the ability to build
their own user controls and add them to my user control folder so that they
can be selected and loaded at run time also. These new controls will need to
have access to many of the classes with there properties and methods within
the complied code. Is this possible? This seems to be the reverse of most
situations where the programmer accesses an object and uses its
functionality. I want my code to dynamically load a new user control created
by a programmer who does not have access to my source code. Is there any
reference material on doing such a thing?

Thanks for you help!!!

Earl


 
Reply With Quote
 
 
 
 
Bruno Sirianni
Guest
Posts: n/a
 
      04-02-2004
With interface file client can compile UserControl code without have your
page code!

If your pages or classes expose a public interface you can do this.

Example :

public interface IA
{
....
void Pippo();
}

public class A : IA
{
...
public void Pippo() { ... };
}

public interface IPublicPageForUser
{
....
IA GetAObject();
}

public MyPage : Page, IPublicPageForUser
{
public IA GetAObject()
{
A aObj = new A();
return (IA)aObj;
}
}


the user control retrieve the object A with :

IA aObj = ((IPublicPageForUser)this.Page).GetAObject()
aObj.Pippo();

I hope that my example is clear and good for your work.

Brun

"Earl Teigrob" <> wrote in message
news:...
> I am writing an application that dynamically loads user controls at run

time
> based on user options. I would like to give my users the ability to build
> their own user controls and add them to my user control folder so that

they
> can be selected and loaded at run time also. These new controls will need

to
> have access to many of the classes with there properties and methods

within
> the complied code. Is this possible? This seems to be the reverse of most
> situations where the programmer accesses an object and uses its
> functionality. I want my code to dynamically load a new user control

created
> by a programmer who does not have access to my source code. Is there any
> reference material on doing such a thing?
>
> Thanks for you help!!!
>
> Earl
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      04-02-2004
Bruno, I've been playing with this for a case very similar to Earl's. Your example is a big help--thank you

One thing, can you or anybody explain the differences/implications of creating an interface versus using operations in the system.reflection class, or is that sort of the same thing? Maybe the difference between early and late binding

For example (vb syntax), from within my user control
Dim mi As System.Reflection.MethodInf
mi = Page.GetType.GetMethod("PageFunction"
mi.Invoke(Page, Nothing

If I have a function called PageFunction on the page that I load this user control from, it gets called from the user control, and I can pass parameters, etc

Any thoughts

Thanks

Bil

Earl, afaik, you're on exactly the right track--getting them from disk at runtime is one of the big advantages of user controls. There's a pretty good discussion of dynamic user controls in Walther's ASP.NET Unleashed book, but it stops short of telling you how to go back and get methods and properties in the parent page

----- Bruno Sirianni wrote: ----

With interface file client can compile UserControl code without have you
page code

If your pages or classes expose a public interface you can do this

Example

public interface I

...
void Pippo()


public class A : I

..
public void Pippo() { ... }


public interface IPublicPageForUse

...
IA GetAObject()


public MyPage : Page, IPublicPageForUse

public IA GetAObject(

A aObj = new A()
return (IA)aObj




the user control retrieve the object A with

IA aObj = ((IPublicPageForUser)this.Page).GetAObject(
aObj.Pippo()

I hope that my example is clear and good for your work

Bru

"Earl Teigrob" <> wrote in messag
news:..
> I am writing an application that dynamically loads user controls at ru

tim
> based on user options. I would like to give my users the ability to buil
> their own user controls and add them to my user control folder so tha

the
> can be selected and loaded at run time also. These new controls will nee

t
> have access to many of the classes with there properties and method

withi
> the complied code. Is this possible? This seems to be the reverse of mos
> situations where the programmer accesses an object and uses it
> functionality. I want my code to dynamically load a new user contro

create
> by a programmer who does not have access to my source code. Is there an
> reference material on doing such a thing
>> Thanks for you help!!
>> Ear
>>

 
Reply With Quote
 
Bruno Sirianni
Guest
Posts: n/a
 
      04-03-2004
Reflection code is slow. With Reflection you can invoche all method and can
see all code! This is not good idea if you don't now who use your code!
If I declare a function private is because this can be used only by my code
class. If another class invoke this function in the wrong way can make
disaster an application, or not?

If your class expose a public interface you can use this without now its
Type.

interface IHello
{
void write();
}

class Hello : IHello //english class
{
public void write()
{
Console.Writeln("Hello");
}
}

class Ciao : IHello //italian class
{
public void write()
{
Console.Writeln( "Ciao");
}
}

//Program
void Begin(IHello h)
{
h.write();
}

if IHello is Ciao class the program write "Ciao" otherwise write "Hello",
but your code never change!

Interface can be compiled in separated project so you can have dll with only
interface and no code. User in this way can develop UserControl without your
code!


Brun

"Bill Borg" <> wrote in message
news:3C468E98-C08A-4408-8E25-...
> Bruno, I've been playing with this for a case very similar to Earl's.

Your example is a big help--thank you!
>
> One thing, can you or anybody explain the differences/implications of

creating an interface versus using operations in the system.reflection
class, or is that sort of the same thing? Maybe the difference between
early and late binding?
>
> For example (vb syntax), from within my user control:
> Dim mi As System.Reflection.MethodInfo
> mi = Page.GetType.GetMethod("PageFunction")
> mi.Invoke(Page, Nothing)
>
> If I have a function called PageFunction on the page that I load this user

control from, it gets called from the user control, and I can pass
parameters, etc.
>
> Any thoughts?
>
> Thanks,
>
> Bill
>
> Earl, afaik, you're on exactly the right track--getting them from disk at

runtime is one of the big advantages of user controls. There's a pretty
good discussion of dynamic user controls in Walther's ASP.NET Unleashed
book, but it stops short of telling you how to go back and get methods and
properties in the parent page.
>
> ----- Bruno Sirianni wrote: -----
>
> With interface file client can compile UserControl code without have

your
> page code!
>
> If your pages or classes expose a public interface you can do this.
>
> Example :
>
> public interface IA
> {
> ....
> void Pippo();
> }
>
> public class A : IA
> {
> ...
> public void Pippo() { ... };
> }
>
> public interface IPublicPageForUser
> {
> ....
> IA GetAObject();
> }
>
> public MyPage : Page, IPublicPageForUser
> {
> public IA GetAObject()
> {
> A aObj = new A();
> return (IA)aObj;
> }
> }
>
>
> the user control retrieve the object A with :
>
> IA aObj = ((IPublicPageForUser)this.Page).GetAObject()
> aObj.Pippo();
>
> I hope that my example is clear and good for your work.
>
> Brun
>
> "Earl Teigrob" <> wrote in message
> news:...
> > I am writing an application that dynamically loads user controls at

run
> time
> > based on user options. I would like to give my users the ability to

build
> > their own user controls and add them to my user control folder so

that
> they
> > can be selected and loaded at run time also. These new controls

will need
> to
> > have access to many of the classes with there properties and

methods
> within
> > the complied code. Is this possible? This seems to be the reverse

of most
> > situations where the programmer accesses an object and uses its
> > functionality. I want my code to dynamically load a new user

control
> created
> > by a programmer who does not have access to my source code. Is

there any
> > reference material on doing such a thing?
> >> Thanks for you help!!!
> >> Earl
> >>



 
Reply With Quote
 
=?Utf-8?B?QmlsbCBCb3Jn?=
Guest
Posts: n/a
 
      04-04-2004
Again, very very helpful, thank you sir

----- Bruno Sirianni wrote: ----

Reflection code is slow. With Reflection you can invoche all method and ca
see all code! This is not good idea if you don't now who use your code
If I declare a function private is because this can be used only by my cod
class. If another class invoke this function in the wrong way can mak
disaster an application, or not

If your class expose a public interface you can use this without now it
Type

interface IHell

void write()


class Hello : IHello //english clas

public void write(

Console.Writeln("Hello")



class Ciao : IHello //italian clas

public void write(

Console.Writeln( "Ciao")



//Progra
void Begin(IHello h

h.write()


if IHello is Ciao class the program write "Ciao" otherwise write "Hello"
but your code never change

Interface can be compiled in separated project so you can have dll with onl
interface and no code. User in this way can develop UserControl without you
code


Bru

"Bill Borg" <> wrote in messag
news:3C468E98-C08A-4408-8E25-..
> Bruno, I've been playing with this for a case very similar to Earl's

Your example is a big help--thank you
>> One thing, can you or anybody explain the differences/implications o

creating an interface versus using operations in the system.reflectio
class, or is that sort of the same thing? Maybe the difference betwee
early and late binding
>> For example (vb syntax), from within my user control

> Dim mi As System.Reflection.MethodInf
> mi = Page.GetType.GetMethod("PageFunction"
> mi.Invoke(Page, Nothing
>> If I have a function called PageFunction on the page that I load this use

control from, it gets called from the user control, and I can pas
parameters, etc
>> Any thoughts
>> Thanks
>> Bil
>> Earl, afaik, you're on exactly the right track--getting them from disk a

runtime is one of the big advantages of user controls. There's a prett
good discussion of dynamic user controls in Walther's ASP.NET Unleashe
book, but it stops short of telling you how to go back and get methods an
properties in the parent page
>> ----- Bruno Sirianni wrote: ----
>> With interface file client can compile UserControl code without hav

you
> page code
>> If your pages or classes expose a public interface you can do this
>> Example
>> public interface I

>
> ...
> void Pippo()
>
>> public class A : I

>
> ..
> public void Pippo() { ... }
>
>> public interface IPublicPageForUse

>
> ...
> IA GetAObject()
>
>> public MyPage : Page, IPublicPageForUse

>
> public IA GetAObject(
>
> A aObj = new A()
> return (IA)aObj
>
>
>>> the user control retrieve the object A with

>> IA aObj = ((IPublicPageForUser)this.Page).GetAObject(

> aObj.Pippo()
>> I hope that my example is clear and good for your work
>> Bru
>> "Earl Teigrob" <> wrote in messag

> news:..
>> I am writing an application that dynamically loads user controls a

ru
> tim
>> based on user options. I would like to give my users the ability t

buil
>> their own user controls and add them to my user control folder s

that
> they
>> can be selected and loaded at run time also. These new controls

will need
> to
>> have access to many of the classes with there properties and

methods
> within
>> the complied code. Is this possible? This seems to be the reverse

of most
>> situations where the programmer accesses an object and uses its
>> functionality. I want my code to dynamically load a new user

control
> created
>> by a programmer who does not have access to my source code. Is

there any
>> reference material on doing such a thing?
>>> Thanks for you help!!!
>>> Earl
>>>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing controls across user controls Vince ASP .Net 3 03-27-2008 11:46 AM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
dynamic user controls in compiled site germ ASP .Net 2 05-04-2007 11:37 PM
accessing symbol tables from compiled code with debug options turned on. Mel C++ 1 12-06-2005 01:45 PM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM



Advertisments
 



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