473,404 Members | 2,213 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,404 software developers and data experts.

AddHandler in C# doesn't work

With ASP.NET 2.0:
In VB code I have added controls dynamically, then added a handler using
AddHandler(Object, Method)
It all works fine.

Now I am trying to do the same in a C# module, but the AddHandler() is not
recognized at all, even though I have tried to add "using
System.ComponentModel;"

I fell like I am missing some basic stuff here, references or ..

Anyone with an idea or a simple example?

Bjorn
Oct 28 '07 #1
5 8751
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Eu*********************@telenor.com...
Anyone with an idea or a simple example?
Google is your friend:
http://www.google.co.uk/search?sourc...%22+AddHandler
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 28 '07 #2
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:us**************@TK2MSFTNGP02.phx.gbl...
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Eu*********************@telenor.com...
>Anyone with an idea or a simple example?

Google is your friend:
http://www.google.co.uk/search?sourc...%22+AddHandler

Thanks. That will certainly help.
I did only search in VS help, without much light beeing lit.

Bjorn
Oct 28 '07 #3
Hi Bjorn,

In C# we use += operator to attach event handlers:

TextBox textBox = new TextBox();
textBox.ID = "txt1";
textBox.Text = "Howdy";
textBox.AutoPostBack = true;
tetxBox.TextChanged += new EventHandler(this.TextChangedHandler);

private void TextChangedHandler(object sender, EventArgs e)
{
// do something here
TextBox textBox = (TextBox) sender;
string text = textBox.Text;
//
}

hope this helps
--
Milosz
"Bjorn Sagbakken" wrote:
With ASP.NET 2.0:
In VB code I have added controls dynamically, then added a handler using
AddHandler(Object, Method)
It all works fine.

Now I am trying to do the same in a C# module, but the AddHandler() is not
recognized at all, even though I have tried to add "using
System.ComponentModel;"

I fell like I am missing some basic stuff here, references or ..

Anyone with an idea or a simple example?

Bjorn
Oct 28 '07 #4
Thanks a lot for the great help.

Bjorn

"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:62**********************************@microsof t.com...
Hi Bjorn,

In C# we use += operator to attach event handlers:

TextBox textBox = new TextBox();
textBox.ID = "txt1";
textBox.Text = "Howdy";
textBox.AutoPostBack = true;
tetxBox.TextChanged += new EventHandler(this.TextChangedHandler);

private void TextChangedHandler(object sender, EventArgs e)
{
// do something here
TextBox textBox = (TextBox) sender;
string text = textBox.Text;
//
}

hope this helps
--
Milosz
"Bjorn Sagbakken" wrote:
>With ASP.NET 2.0:
In VB code I have added controls dynamically, then added a handler using
AddHandler(Object, Method)
It all works fine.

Now I am trying to do the same in a C# module, but the AddHandler() is
not
recognized at all, even though I have tried to add "using
System.ComponentModel;"

I fell like I am missing some basic stuff here, references or ..

Anyone with an idea or a simple example?

Bjorn

Oct 29 '07 #5
AddHandler() in VB is equivalent to:

controlToAddTo.EventToHandle += new EventHandler();

If you want to look up anything, check wiring delegates, or similar, as this
is fairly basic work with delegates (events are delegates in C# -- a bit of
an oversimplification, but it works until you get more advanced).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Eu*********************@telenor.com...
With ASP.NET 2.0:
In VB code I have added controls dynamically, then added a handler using
AddHandler(Object, Method)
It all works fine.

Now I am trying to do the same in a C# module, but the AddHandler() is not
recognized at all, even though I have tried to add "using
System.ComponentModel;"

I fell like I am missing some basic stuff here, references or ..

Anyone with an idea or a simple example?

Bjorn

Oct 29 '07 #6

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

Similar topics

5
by: Marina | last post by:
Hi, I have a component that implements ISupportInitialize, so the code in InitializeComponent is something like: theComponent.BeginInit() ' Set theComponent properties ...
0
by: Micke Palm | last post by:
Hello! Do anyone have good experince of AddHandler? I create a LinkButton in a function and the function will be called from page_load. I need to have the call inside ispostback if. The...
7
by: UGH | last post by:
I am adding image buttons dynamically and I need to add event handler when the user clicks on one of those image buttons which will have different id for reports. Here is my code LnkImage =...
10
by: Rick Palmer | last post by:
I have an app I'm working on that will allow a user to run one of 5 reports. The report names are in a combobox on my form. I have a sub defined for each report that has the exact same name as is...
5
by: eBob.com | last post by:
I've used AddHandler for a UNIQUE control added to a panel and it seemed to work. But now I want to add a bunch of controls to a panel and use only one event handler subroutine. And I am...
3
by: Vemund Halvorsen | last post by:
Hi, Im having some trouble getting Addhandler to work. Using withevents everything is working fine. But with AddHandler I get no callback. The code below works fin if I declare _tcp as a...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
5
by: Slim | last post by:
i have a simple page, with one button button1. when click it creates a new button button 2 and adds a event handler to it. but when button 2 is clicked nothing happens, why? Partial Class...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.