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

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
 
G

Guest

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
 
L

Learner

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
 
G

Guest

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.
 
L

Learner

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
 
G

Guest

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)
 
L

Learner

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top