开发者

Why Custom event handler raising two times in asp.net?

i have created a custom event and assigned a handler to it .

the line which raises event is called one time but handler is getting called

TWO times , w开发者_开发百科hy it is so ?

Please help ?


If the event was attached two times then when you raise the event the event handler will be called two times. For example

public void MyEventHandler(object sender, EventArgs e) {
}

...

someObject.SomeEvent += MyEventHandler;
someObject.SomeEvent += MyEventHandler;

...

someObject.RaiseSomeEvent();

This will cause MyEventHandler to be called twice. How sure are you that the event is being attached only once?


You might want to consider that some other operations could trigger events that you handle, like for instance when you bind data to a combo box, it will automatically raise the OnSelectionChange event.

So you could have a scenario where OnLoad you bind data to the combo so you event gets raised, and OnInit you assign some default value to the combo which raises the event again.

Without some code from you, this can only help you realize that this problem can happen in many ways.

So let's see the code please! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜