Onclick in buttons causes bug?

C

COHENMARVIN

I created asp.net pages that contained several controls, including
buttons. I would double click on the button, and this would take me
to the 'code-behind' page, and create the shell of a routine to handle
that button click. What I found later though, was that this routine
was being executed twice. So I looked into it, and I found that the
button had a 'onclick' attribute which was pointing to the routine,
but also, the routine had a 'handles' clause, that pointed to the
button. So the routine was being executed twice, and I had to get rid
of the 'onclick' attribute.
The mystery is, how did the 'onclick' attribute get into the button.
A few days later, I looked at a page that had always worked, and this
time a gridview associated routine was being executed twice, and
causing a bug. The cause was similar - there was a routine with a
handles clause that pointed to the gridview, but the gridview also had
a 'onselected' type attribute that pointed to the routine.
The mystery is, how did this 'onselected' attribute get into the
gridview. I certainly didn't put it there on purpose.
So is there some bug in asp.net where if you click on some control
accidentally, you prefill it with an 'onclick' event?
Thanks,
Marvin
 
S

subtile

Are you using Visual Studio ?

If you double click your button in design view VS will automatically create
an onclink event. It's the same with the gridview.. Code will not be added
thoug but a click will create a postback (in non ajax applications)
 
M

Munna

Hi Marvin
Very interesting point you have raised...
well after reading your post i did a little investigation on that...

if i use a webproject of language "c#" ... when i double click on the
button it create a markup like
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
and in code behind a method is been created.. for handling the button
click..

then i used a webproject of language "vb" this time button markup
remains same and ...
<asp:Button ID="Button1" runat="server" Text="Button" />
and in code behind file a handler is created...

I am sure no other code is create for that.. but adding onclick
manually on vb project again
does fires event handler twice...

may we know which version of vs you are using...?

Thanks

Munna
 
C

COHENMARVIN

Hi Marvin
Very interesting point you have raised...
well after reading your post i did a little investigation on that...

if i use a webproject of language "c#" ... when i double click on the
button it create a markup like
<asp:Button ID="Button1" runat="server"  Text="Button"
onclick="Button1_Click" />
and in code behind a method is been created.. for handling the button
click..

then i used a webproject of language "vb" this time button markup
remains same and ...
<asp:Button ID="Button1" runat="server" Text="Button" />
and in code behind file a handler is created...

I am sure no other code is create for that.. but adding onclick
manually on vb project again
does fires event handler twice...

may we know which version of vs you are using...?

Thanks

Munna

I'm using VS 2005, and I'm programming in VB. So you are saying that
in VB, clicking on the button does not insert an 'onclick' statement
in the HTML, but in C# it does?
Thanks.
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top