473,387 Members | 1,465 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.

Remove Handler.. & Add Handler...

VJ
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both
the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove
Handler not removing the old method and adding a new one for the same click
event. Anybody have ideas??

Thanks
VJ
Nov 20 '05 #1
5 4073
It doesent remove the method, it simply attaches/removes the method to the
event.

Regards - OHM
"VJ" <vi********@yahoo.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove Handler not removing the old method and adding a new one for the same click event. Anybody have ideas??

Thanks
VJ

Nov 20 '05 #2
I tried this out, both Labels have their clicks serviced until button one is
pressed, then only label2 works.
\\
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click

MessageBox.Show("Label1.Clicked")

End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label2.Click

MessageBox.Show("Label2.Clicked")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

RemoveHandler Label1.Click, AddressOf Label1_Click

End Sub
//
Regards - OHM


"VJ" <vi********@yahoo.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove Handler not removing the old method and adding a new one for the same click event. Anybody have ideas??

Thanks
VJ

Nov 20 '05 #3
* "VJ" <vi********@yahoo.com> scripsit:
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both
the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove
Handler not removing the old method and adding a new one for the same click
event.


What's 'Condition1' and 'Condition2'? Your code should work.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
VJ
Its just a whether a menu is checked or not... that is it.. The code does
not work.. I tried possibilities I know.. but it keeps the click event..

VJ

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
* "VJ" <vi********@yahoo.com> scripsit:
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove Handler not removing the old method and adding a new one for the same click event.


What's 'Condition1' and 'Condition2'? Your code should work.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5
VJ
What happens if I do this?.. is there 2 refrences in memory?

AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem

Thanks
VJ

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
* "VJ" <vi********@yahoo.com> scripsit:
Here is snippet of my problem

IF Condition1 then
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowItem
AddHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
elseif Condition2 then
AddHandler lblCntrl.Click, AddressOf lbl_ShowItem
RemoveHandler lblCntrl.Click, AddressOf lbl_ShowMaker2
end if

After the above block is executed I try to click on the label.. I have both the "lbl_ShowItem" and "lbl_ShowMaker2" methods executed. I had to go
include the same IF check inside each method to prevent... Why is the Remove Handler not removing the old method and adding a new one for the same click event.


What's 'Condition1' and 'Condition2'? Your code should work.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #6

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

Similar topics

9
by: middletree | last post by:
I have a page which takes data in an HTML table, and exports it to an Excel file. It works fine, but I want several things about the spreadsheet to look different from the HTML version. Things like...
7
by: Kieran Simkin | last post by:
Hi all, I'm having some trouble with a linked list function and was wondering if anyone could shed any light on it. Basically I have a singly-linked list which stores pid numbers of a process's...
3
by: Franco, Gustavo | last post by:
How can I remove all event handler from one event without do -=? I won't explain why because is too long, and that the only option left I have right now. I have one event declared for: ...
3
by: Peter Oliphant | last post by:
In general, some controls can have events handlers attached to them, typically via the += operator. How does one remove an event handler added this way? Or, just as good for my purposes, how can...
4
by: Charles Law | last post by:
Is there a way to dynamically remove an event handler from an event without knowing the name of the handler? For example, how can ClassB remove the handler without knowing the name, or how many...
10
by: Franky | last post by:
How Remove All Handler on a event? Like remove all handler on the myButton.Click. Thanks ______________________________ Franky FrankyPDA_NOSPAM_@hotmail.com
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
0
by: dolittle | last post by:
Hi, I'm embedding a last.fm flash widget. I want to be able to remove it from the page using javascript. I've tried to delete the html element that contains the code but it keeps playing in...
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
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?
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
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...

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.