Re: Function executed twice
- From: "Nathan Sokalski" <njsokalski@xxxxxxxxxxx>
- Date: Fri, 16 Feb 2007 13:57:37 -0500
I have never had that happen, but I am going to guess that there is a setting somewhere in Visual Studio that you accidentally changed which is causing it to add the onclick="Button_Click" that you don't want. I don't know what it is, but you may want to try posting this to one of the groups such as microsoft.public.vsnet.debugging or microsoft.public.vsnet.general, those groups might know more about the Visual Studio settings than me.
I would also like to say, just in case you don't do it already, that using prefixes for your control ids can make it easier when working in code. For example, when I create a textbox field on a form, I might use the following ids:
lblUsername (for the Label that tells the user what to enter in the field)
txtUsername (for the TextBox)
rfvUsername (for the RequiredFieldValidator)
revUsername (for the RegularExpressionValidator)
This way, there is less to remember because all the fields' ids have very similar ids, but you can tell which one is which by looking at the prefix. It can also help you remember what type of control each one is. You can obviously choose whatever you want for the prefixes, but once you start using them, it can make things much easier. (some of the other prefixes I use are btn, img, lnk, ddl, chk, pnl) This may not eliminate the need to look back at the Design View (it didn't for me either), but it will definitely reduce it. Good Luck!
--
Nathan Sokalski
njsokalski@xxxxxxxxxxx
http://www.nathansokalski.com/
"Bruno Alexandre" <bruno.in.dk@xxxxxxxxx> wrote in message news:uDX8bWcUHHA.4844@xxxxxxxxxxxxxxxxxxxxxxx
I always choose the easy way, double click the link/button, and because the onCLick event is the default event it will create me the function Handles Button.Click but it also adds to the button tag onclick="Button_Click" and the browser perform that event twice, I guess one for what's in the tag and other for the Handles part ...
and it should only place one, or the tag or the handle (for me will be easier to only add the handle)
ohhh well, I will do like you said, but off course, with so much controls I always need to jump from design view to code just to remember the button name
but thans anyway.
--
Bruno Alexandre
Strøby, Danmark
"a Portuguese in Denmark"
"Nathan Sokalski" <njsokalski@xxxxxxxxxxx> wrote in message news:eIeRrkMUHHA.5016@xxxxxxxxxxxxxxxxxxxxxxx
I'm not sure how you're managing to get VS2005 to add the onClick=ButtonName_Click to the Button tag, but that is not necessary to be there. Also, it sounds like you are adding the events the wrong way. The easiest and best way to add an event using Visual Studio .NET 2005 is to do the following:
1. Open the codebehind file
2. In the first dropdownlist above the code, select the Control that you want to create an event for (such as Button1)
3. In the second dropdownlist above the code, select the event you want to create (such as Click)
4. You do NOT need to add anything to the tag in the *.aspx file
For some Controls, there is a default event. For example, the Button Control's default event is the Click event. This means that to create the Click event, you can double-click the Button in Design View and it will take you to the event handler for that Button's Click event in the codebehind. Hopefully this will make things easier for you. Good Luck!
--
Nathan Sokalski
njsokalski@xxxxxxxxxxx
http://www.nathansokalski.com/
"Bruno Alexandre" <bruno.in.dk@xxxxxxxxx> wrote in message news:902FEC14-5DAF-4527-8C97-D73593494D4F@xxxxxxxxxxxxxxxx
> Hi guys,
>
> from some time I have a problem in my ASPX pages (2.0)
> when I drag a LinkButton or Button or Whatever and then I go to server
> propreties and click twice on the event onClick
>
> the Visual Studio 2005 places ButtonName_Click inside the button tag and in
> the code behing file gives-me
>
> ButtonName_CLick( bla bla ) Handles ButtonName.Click
>
> if inside this event I just write something to the database (even a simple
> response.write("HEllO<hr/>")) and then I execute the page, and click in the
> link/button I get the page to write 2 times that phrase !!!
>
> if I delete the event from the button FINE
> if I delete the Handles ButtonName.Click FINE
>
>
> but by default VS2k5 add this two and I need to delete one everytime before
> saving the file, cause if I want to navigate from design to code in
> code-behid I usually click twice in the link/button and that will ADD the
> event onCLick in the tag and the Handles in the code behind...
>
> Does anyone cross with this error? what do I have to do do have only one
> single event even with both events on the TAG and the CODE-BEHIND ?
>
> my header page always starts with:
> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default"
> LCID="1030" Strict="true" Explicit="true" %>
>
> any ideas?
> --
>
> Bruno Alexandre
> Stroby, Danmark
>
> "a Portuguese in Denmark"
>
>
>
- References:
- Function executed twice
- From: Bruno Alexandre
- Re: Function executed twice
- From: Nathan Sokalski
- Re: Function executed twice
- From: Bruno Alexandre
- Function executed twice
- Prev by Date: Re: crosspage posting (smallish) problem
- Next by Date: Form.DefaultButton stopped working in firefox
- Previous by thread: Re: Function executed twice
- Next by thread: Releasing file locks
- Index(es):

