Dynamic event handlers and code

Discussion in 'ASP .Net' started by Chris, Aug 23, 2006.

  1. Chris

    Chris Guest

    Is there any way you can dynamically add an event and then some code. I get
    it that you could, in your code, add a control and dynamically add an event
    handler for e.g. the click event. However the code within the event handler,
    could that be pulled from a database and ran.

    I would like to create a form in which I could populate it's controls and
    events based on config information in either a database or xml file e.g. how
    many textboxes amd dropdowns on the page. I know I can do this but what
    would really make it useful would be to dynamically add the code within the
    events. Is that possible? Regards, Chris.
    Chris, Aug 23, 2006
    #1
    1. Advertising

  2. You would have to pull the code from a database, compile it. Then
    instantiate the object that code is defining using reflection , call a
    method on it using reflection.

    This is all very complicated, however, and does not perform well. I don't
    know what problem you are trying to solve, but I would recommend trying to
    revisit your requirements and seeing if there is another way to accomplish
    what you want.

    "Chris" <> wrote in message
    news:e%...
    > Is there any way you can dynamically add an event and then some code. I
    > get it that you could, in your code, add a control and dynamically add an
    > event handler for e.g. the click event. However the code within the event
    > handler, could that be pulled from a database and ran.
    >
    > I would like to create a form in which I could populate it's controls and
    > events based on config information in either a database or xml file e.g.
    > how many textboxes amd dropdowns on the page. I know I can do this but
    > what would really make it useful would be to dynamically add the code
    > within the events. Is that possible? Regards, Chris.
    >
    Marina Levit [MVP], Aug 23, 2006
    #2
    1. Advertising

  3. Chris

    Chris Guest

    Yes I had a feeling that it wouldn't be straight forward hence the early
    post. The idea would be to have a composite control which pulls in an XML
    config file which would contain instructions on how to create a form e.g.
    text boxs drop down. The idea being you could point the control at different
    XML files and use it to dynamically generate your forms rather than hand
    creating them all the time. It's just some of the controls may well need
    events and event code which is different for each form. It's just an idea
    I've been toying with, as we have a system which has LOTS of versions of a
    similar form and I was looking at ways of generating the forms which are
    less code intensive. Does anyone ever use self generating form? Regards,
    Chris.

    "Marina Levit [MVP]" <> wrote in message
    news:%...
    > You would have to pull the code from a database, compile it. Then
    > instantiate the object that code is defining using reflection , call a
    > method on it using reflection.
    >
    > This is all very complicated, however, and does not perform well. I don't
    > know what problem you are trying to solve, but I would recommend trying to
    > revisit your requirements and seeing if there is another way to accomplish
    > what you want.
    >
    > "Chris" <> wrote in message
    > news:e%...
    >> Is there any way you can dynamically add an event and then some code. I
    >> get it that you could, in your code, add a control and dynamically add an
    >> event handler for e.g. the click event. However the code within the event
    >> handler, could that be pulled from a database and ran.
    >>
    >> I would like to create a form in which I could populate it's controls and
    >> events based on config information in either a database or xml file e.g.
    >> how many textboxes amd dropdowns on the page. I know I can do this but
    >> what would really make it useful would be to dynamically add the code
    >> within the events. Is that possible? Regards, Chris.
    >>

    >
    >
    Chris, Aug 23, 2006
    #3
  4. Hello Chris,

    A bit off subject but what you want to do sounds like XAML (Extensible
    Application Markup Language) which is supposed to be an important feature of
    version 3.0 of the .NET Framemork. For a bit more info:

    http://en.wikipedia.org/wiki/XAML
    http://www.xaml.net
    http://www.google.com/search?hl=en&q=xaml

    --
    enjoy - brians
    http://www.limbertech.com


    "Chris" wrote:

    > Yes I had a feeling that it wouldn't be straight forward hence the early
    > post. The idea would be to have a composite control which pulls in an XML
    > config file which would contain instructions on how to create a form e.g.
    > text boxs drop down. The idea being you could point the control at different
    > XML files and use it to dynamically generate your forms rather than hand
    > creating them all the time. It's just some of the controls may well need
    > events and event code which is different for each form. It's just an idea
    > I've been toying with, as we have a system which has LOTS of versions of a
    > similar form and I was looking at ways of generating the forms which are
    > less code intensive. Does anyone ever use self generating form? Regards,
    > Chris.
    >
    =?Utf-8?B?YnJpYW5zW01DU0Rd?=, Aug 23, 2006
    #4
  5. Chris

    Chris Guest

    It looks interesting but my solution needs to be fully accessible to people
    with disabilities. :)

    "brians[MCSD]" <> wrote in message
    news:...
    > Hello Chris,
    >
    > A bit off subject but what you want to do sounds like XAML (Extensible
    > Application Markup Language) which is supposed to be an important feature
    > of
    > version 3.0 of the .NET Framemork. For a bit more info:
    >
    > http://en.wikipedia.org/wiki/XAML
    > http://www.xaml.net
    > http://www.google.com/search?hl=en&q=xaml
    >
    > --
    > enjoy - brians
    > http://www.limbertech.com
    >
    >
    > "Chris" wrote:
    >
    >> Yes I had a feeling that it wouldn't be straight forward hence the early
    >> post. The idea would be to have a composite control which pulls in an XML
    >> config file which would contain instructions on how to create a form e.g.
    >> text boxs drop down. The idea being you could point the control at
    >> different
    >> XML files and use it to dynamically generate your forms rather than hand
    >> creating them all the time. It's just some of the controls may well need
    >> events and event code which is different for each form. It's just an idea
    >> I've been toying with, as we have a system which has LOTS of versions of
    >> a
    >> similar form and I was looking at ways of generating the forms which are
    >> less code intensive. Does anyone ever use self generating form? Regards,
    >> Chris.
    >>

    >
    Chris, Aug 23, 2006
    #5
  6. Well, I think you can still do what you describe. You can parse an XML file,
    and based on that, create the appropriate controls.

    What you can do, is have all the methods you will ever need compiled into a
    class. Then, using reflection, find the appropriate method you need (as
    specified in the XML file), and attach that as the event handler. Or, have
    your own generic event handler for everything, that based on the object that
    raised the event, uses reflection to find the appropriate method, and invoke
    it (I sort of like this one better).

    "Chris" <> wrote in message
    news:...
    > Yes I had a feeling that it wouldn't be straight forward hence the early
    > post. The idea would be to have a composite control which pulls in an XML
    > config file which would contain instructions on how to create a form e.g.
    > text boxs drop down. The idea being you could point the control at
    > different XML files and use it to dynamically generate your forms rather
    > than hand creating them all the time. It's just some of the controls may
    > well need events and event code which is different for each form. It's
    > just an idea I've been toying with, as we have a system which has LOTS of
    > versions of a similar form and I was looking at ways of generating the
    > forms which are less code intensive. Does anyone ever use self generating
    > form? Regards, Chris.
    >
    > "Marina Levit [MVP]" <> wrote in message
    > news:%...
    >> You would have to pull the code from a database, compile it. Then
    >> instantiate the object that code is defining using reflection , call a
    >> method on it using reflection.
    >>
    >> This is all very complicated, however, and does not perform well. I
    >> don't know what problem you are trying to solve, but I would recommend
    >> trying to revisit your requirements and seeing if there is another way to
    >> accomplish what you want.
    >>
    >> "Chris" <> wrote in message
    >> news:e%...
    >>> Is there any way you can dynamically add an event and then some code. I
    >>> get it that you could, in your code, add a control and dynamically add
    >>> an event handler for e.g. the click event. However the code within the
    >>> event handler, could that be pulled from a database and ran.
    >>>
    >>> I would like to create a form in which I could populate it's controls
    >>> and events based on config information in either a database or xml file
    >>> e.g. how many textboxes amd dropdowns on the page. I know I can do this
    >>> but what would really make it useful would be to dynamically add the
    >>> code within the events. Is that possible? Regards, Chris.
    >>>

    >>
    >>

    >
    >
    Marina Levit [MVP], Aug 24, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boban Dragojlovic

    Dynamic Buttons and Event Handlers, revisited

    Boban Dragojlovic, Jun 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,858
    Boban Dragojlovic
    Jun 24, 2003
  2. noone

    Handlers and dynamic buttons

    noone, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    291
    Natty Gur
    Jan 27, 2004
  3. Mark Goldin

    Client event handlers and parameters

    Mark Goldin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,635
    Mark Goldin
    Feb 22, 2004
  4. =?Utf-8?B?Tm92aWNl?=
    Replies:
    1
    Views:
    456
    John Saunders
    Sep 23, 2004
  5. =?Utf-8?B?U2hpanUgUG95aWxpbA==?=

    Problem with Event handlers for Dynamic created Controls in DatGri

    =?Utf-8?B?U2hpanUgUG95aWxpbA==?=, May 10, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    589
Loading...

Share This Page