My button click event runs twice in my VS 2005 - need help

  • Thread starter Thread starter Learner
  • Start date Start date
L

Learner

Hello,

I converted a VS 2003 project to VS 2005. It works perfectly
alright in VS 2003 but when I try running in VS 2005 I got strange
thing going on. The code (my button click event ) runs twice? Has any
one run into this kind of situation before please help. Am I missing
some thing here? or do I need to set an option here?

Thanks,
-L
 
Hello,

I converted a VS 2003 project to VS 2005. It works perfectly
alright in VS 2003 but when I try running in VS 2005 I got strange
thing going on. The code (my button click event ) runs twice? Has any
one run into this kind of situation before please help. Am I missing
some thing here? or do I need to set an option here?

Thanks,
-L

What the code of the click event? If something like this

Sub Button_Click(...) Handles Button.Click

try to get rid of the Handles Button.Click
 
What the code of the click event? If something like this

Sub Button_Click(...) Handles Button.Click

try to get rid of the Handles Button.Click

Yes if I remove the handles.button click event then works fine. Is
this a new change in VS 2005? I don't think if it fires the event if
we remove it in VS 2003 will it?

Thanks
-L
 
Yes if I remove the handles.button click event then works fine. Is
this a new change in VS 2005? I don't think if it fires the event if
we remove it in VS 2003 will it?

VS 2005 creates an event handler using an additional attribute/value:

<asp:Button ID="Button" runat="server" OnClick="Button_Click" />

and when you have

Sub Button_Click(...) Handles Button.Click

you wired an event to a control twice.
 
it's new in ASP.NET 2.0

Hi Alexey,

So you mean in VS 2003 we don't see some thing like this

<asp:Button ID="Button" runat="server" OnClick="Button_Click" />

and jsut

<asp:Button ID="Button" runat="server"/> then? and that is why it
doesn't work if we do not have "Handles btnAdd.Click"?

Good explanation.

Thanks,
-L
 
Hi Alexey,

So you mean in VS 2003 we don't see some thing like this

<asp:Button ID="Button" runat="server" OnClick="Button_Click" />

and jsut

<asp:Button ID="Button" runat="server"/> then? and that is why it
doesn't work if we do not have "Handles btnAdd.Click"?

Good explanation.

Thanks,
-L

It will work in VS 2003. But by default the old IDE wires an event to
a control using Handles <control>.<event> (VB.NET) and Button.Click +=
new System.EventHandler(this.Button_Click) (C#). For some reasons they
decided to change this since ASP.NET 2.0 and VS 2005 by default uses
OnClick=<function> and it was a reason why you had the event fired
twice.

In general, you have to understand when the event runs twice then
there is something wrong with its handler.

Hope it helps (I think I have to look in MSDN to find more clear info
regarding this matter)
 
It will work in VS 2003. But by default the old IDE wires an event to
a control using Handles <control>.<event> (VB.NET) and Button.Click +=
new System.EventHandler(this.Button_Click) (C#). For some reasons they
decided to change this since ASP.NET 2.0 and VS 2005 by default uses
OnClick=<function> and it was a reason why you had the event fired
twice.

In general, you have to understand when the event runs twice then
there is something wrong with its handler.

Hope it helps (I think I have to look in MSDN to find more clear info
regarding this matter)- Hide quoted text -

- Show quoted text -

Great Thank you.

-L
 
Back
Top