473,387 Members | 3,820 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,387 software developers and data experts.

Binding events to dynamic controls

I am trying to bind a click event to a check box control
that I create during page load. I have tried using the
this.controlname += new System.EventHandler
(this.controlname_Click); but it tells me that my form
does not contain a definition for that control. I create
this control for infomation that I pull from a database
so there are multiple instances of this control, all with
a different id property. How can I tie an event handler
to these controls.
Nov 15 '05 #1
4 10254
Jeremy,

You can use the GetEvent method on the Type to get the EventInfo that
represents the event. Once you have that, you can call the AddEventHandler
method on the EventInfo instance to add the event to the control.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Ames" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...
I am trying to bind a click event to a check box control
that I create during page load. I have tried using the
this.controlname += new System.EventHandler
(this.controlname_Click); but it tells me that my form
does not contain a definition for that control. I create
this control for infomation that I pull from a database
so there are multiple instances of this control, all with
a different id property. How can I tie an event handler
to these controls.

Nov 15 '05 #2
I am not having much luck figuring this out. I am looking
at the MSDN library and I see an example but I am not
really understanding the example. Could you show me an
example?

-----Original Message-----
Jeremy,

You can use the GetEvent method on the Type to get the EventInfo thatrepresents the event. Once you have that, you can call the AddEventHandlermethod on the EventInfo instance to add the event to the control.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Ames" <an*******@discussions.microsoft.com> wrote in messagenews:12****************************@phx.gbl...
I am trying to bind a click event to a check box control that I create during page load. I have tried using the
this.controlname += new System.EventHandler
(this.controlname_Click); but it tells me that my form
does not contain a definition for that control. I create this control for infomation that I pull from a database
so there are multiple instances of this control, all with a different id property. How can I tie an event handler
to these controls.

.

Nov 15 '05 #3
Jeremy,

Say you have a button with the Click event stored in an object. You can
get the event like this:

// Get the EventInfo. The button is in the mobjControl variable and is of
type object.
EventInfo pobjClickEvent = mobjControl.GetType().GetEvent("Click");

Then you can add the event handler:

// Add the event handler.
pobjClickEvent.AddEventHandler(mobjControl, new
EventHandler(this.controlname_Click));
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Ames" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
I am not having much luck figuring this out. I am looking
at the MSDN library and I see an example but I am not
really understanding the example. Could you show me an
example?

-----Original Message-----
Jeremy,

You can use the GetEvent method on the Type to get

the EventInfo that
represents the event. Once you have that, you can call

the AddEventHandler
method on the EventInfo instance to add the event to the

control.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Ames" <an*******@discussions.microsoft.com>

wrote in message
news:12****************************@phx.gbl...
I am trying to bind a click event to a check box control that I create during page load. I have tried using the
this.controlname += new System.EventHandler
(this.controlname_Click); but it tells me that my form
does not contain a definition for that control. I create this control for infomation that I pull from a database
so there are multiple instances of this control, all with a different id property. How can I tie an event handler
to these controls.

.

Nov 15 '05 #4
Thanks for the example, I really appreciate it. However,
I am getting errors on the second line of that code. This
is what I have:

EventInfo oCheckEvent = chkComplete.GetType
().GetEvent("Click");
oCheckEvent.AddEventHandler(chkComplete, new
EventHandler( this.chkComplete_Click));

The error message that I am receiving is "Object
reference not set to an instance of an object." This does
not make sense to me. I would think that oCheckEvent
would have been instantiated in the first line. Do you
have any suggestions?
-----Original Message-----
Jeremy,

Say you have a button with the Click event stored in an object. You canget the event like this:

// Get the EventInfo. The button is in the mobjControl variable and is oftype object.
EventInfo pobjClickEvent = mobjControl.GetType().GetEvent ("Click");
Then you can add the event handler:

// Add the event handler.
pobjClickEvent.AddEventHandler(mobjControl, new
EventHandler(this.controlname_Click));
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeremy Ames" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
I am not having much luck figuring this out. I am looking at the MSDN library and I see an example but I am not
really understanding the example. Could you show me an
example?

>-----Original Message-----
>Jeremy,
>
> You can use the GetEvent method on the Type to get

the EventInfo that
>represents the event. Once you have that, you can call
the AddEventHandler
>method on the EventInfo instance to add the event to
the control.
>
> Hope this helps.
>
>
>--
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
>"Jeremy Ames" <an*******@discussions.microsoft.com>

wrote in message
>news:12****************************@phx.gbl...
>> I am trying to bind a click event to a check box

control
>> that I create during page load. I have tried using

the >> this.controlname += new System.EventHandler
>> (this.controlname_Click); but it tells me that my form >> does not contain a definition for that control. I

create
>> this control for infomation that I pull from a database >> so there are multiple instances of this control, all

with
>> a different id property. How can I tie an event handler >> to these controls.
>
>
>.
>

.

Nov 15 '05 #5

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

Similar topics

1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
2
by: Michael Ramey | last post by:
Howdy, I think I have a good question! I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
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...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
5
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is...
7
by: msdev | last post by:
Hello, I am creating my own webbrowser to learn VB .Net. I am stuck on an issue with regards to dynamically-created controls, in this case tabs on a tabcontrol and webbrowsers created within...
0
by: JohnS | last post by:
Hi! This may well have been asked before, but how do you best catch events from dynamic controls in ASP.NET i.e. those created and placed programatically? An example page layout: Initially: ...
3
by: HP | last post by:
Hi there The problem of dynamically created controls vs viewstate is widely known one. To access values of controls they have to be recreated on Page_Load. Unfortunately it causes many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.