Onclick in buttons causes bug?

Discussion in 'ASP .Net' started by COHENMARVIN@lycos.com, Jun 11, 2008.

  1. Guest

    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
    , Jun 11, 2008
    #1
    1. Advertising

  2. subtile Guest

    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


    "" 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
    >
    subtile, Jun 11, 2008
    #2
    1. Advertising

  3. Munna Guest

    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
    Munna, Jun 11, 2008
    #3
  4. Guest

    On Jun 11, 9:57 am, Munna <> 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.
    , Jun 12, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Osa
    Replies:
    0
    Views:
    628
    Xavier Osa
    Jan 9, 2004
  2. jason9364
    Replies:
    0
    Views:
    850
    jason9364
    Nov 19, 2007
  3. bob
    Replies:
    3
    Views:
    183
  4. Replies:
    2
    Views:
    252
  5. Replies:
    4
    Views:
    175
Loading...

Share This Page