473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dynamic event handlers and code

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.
Aug 23 '06 #1
5 1404
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" <no****@btinternet.comwrote in message
news:e%****************@TK2MSFTNGP02.phx.gbl...
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.

Aug 23 '06 #2
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]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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" <no****@btinternet.comwrote in message
news:e%****************@TK2MSFTNGP02.phx.gbl...
>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.


Aug 23 '06 #3
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.
Aug 23 '06 #4
It looks interesting but my solution needs to be fully accessible to people
with disabilities. :)

"brians[MCSD]" <br********@discussions.microsoft.comwrote in message
news:C5**********************************@microsof t.com...
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.

Aug 23 '06 #5
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" <no****@btinternet.comwrote in message
news:u4**************@TK2MSFTNGP03.phx.gbl...
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]" <so*****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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" <no****@btinternet.comwrote in message
news:e%****************@TK2MSFTNGP02.phx.gbl...
>>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.



Aug 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
2
by: Mark Broadbent | last post by:
I had a requirement to code dynamic delegates, so they attach detach from the button as needed ... then after time realised that the button is not retaining it's click handlers. To circumvent this...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
2
by: Shiju Poyilil | last post by:
I have a link button "lButton" created dynamically at the item databound event of the data grid "datagrid1" in the footer.so i want to execute the item command event of the datagrid on clicking...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
3
by: Kris Palmer | last post by:
hi, can somebody explain this problem? it's driving me crazy! i have a requirement to dynamically create a variable quantity of timers with associated start button based on the contents of a...
3
by: =?Utf-8?B?ZWFndWlsYXI=?= | last post by:
Hi, I am trying to dynamically generate a menu, based on entries on a text or xml file. The text file contains the "tree" after which the menu will need to be created. Something like the...
0
by: galien8 | last post by:
Dear Newsgroup Readers, I have a problem with dynamic controls, in a DotNetNuke module, and event handlers in VB.NET ASP.NET 2.0. Events are firing and being handled, sometimes good but also...
3
balabaster
by: balabaster | last post by:
I've got a user control that builds a table of dynamic data based on a :LINQ class holding the data. The data is loaded using the LoadData(DataInstance) method. The table it builds contains a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.