Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Onclick in buttons causes bug? (http://www.velocityreviews.com/forums/t619646-onclick-in-buttons-causes-bug.html)

COHENMARVIN@lycos.com 06-11-2008 12:07 PM

Onclick in buttons causes bug?
 
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

subtile 06-11-2008 12:36 PM

RE: Onclick in buttons causes bug?
 
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)

--

Jesus Loves You


"COHENMARVIN@lycos.com" wrote:

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


Munna 06-11-2008 01:57 PM

Re: Onclick in buttons causes bug?
 
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


COHENMARVIN@lycos.com 06-12-2008 12:21 PM

Re: Onclick in buttons causes bug?
 
On Jun 11, 9:57*am, Munna <munna...@gmail.com> wrote:
> 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.


All times are GMT. The time now is 09:45 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.