Last post Jul 29, 2015 12:05 PM by Ernesto Ono
Dec 20, 2006 05:03 PM|krugs525|LINK
Dec 21, 2006 09:42 AM|Rohit Gupta|LINK
you need to post your sample code which fires an event twice
Dec 23, 2006 11:24 PM|vbuser2004|LINK
One possible reason: Check your button declaration in your .aspx source. If you have a 'runat=server' and onclick="button1_click", and you have an event handler in your code-behind (ie. .aspx.vb), it will cause the event to be fired twice. Here is an
example in xxx.aspx:
<asp:Button id="button1" onclick="button1_Click" runat="server"
This declaration should be:
<asp:Button id="button1" runat="server" Text="Click Me!"></asp:Button>
Aug 09, 2007 03:08 AM|maheshwd|LINK
You are right I face the same problem, and thanks for your post above, I solve this issue by the above post
May 29, 2008 10:43 AM|in2minds|LINK
you are a saviour, i have been wondering why my event was firing two times, and i was suspecting AJAX Accordian panel. But when i removed the on lcik from .aspx page it works like a charm.
May 29, 2008 11:15 PM|chetan.sarode|LINK
Aug 01, 2008 11:23 AM|iupchris10|LINK
I disagree with the posted solution.
The reason the event is firing twice is because you have an "OnClick" attribute AND an event handler in code behind.
OnClick = "btnLogin_Click"
You will find the event handler in a region called "Web Form Designer generated code". This was the OLD way .NET handled events for buttons. ASP .NET 3.5 now creates
OnClick for all new buttons.
To keep your code consistent, I would argue that the better way to fix the problem is to
delete the Event Handler in Code Behind, not the OnClick attribute.
Anyone agree with this?
Aug 03, 2008 11:16 PM|chetan.sarode|LINK
Pages support an automatic way to bind their events to methods.
If the AutoEventWireup attribute of the @ Page directive is set to true (or if it is missing, because by default it is true), page events are automatically
bound to methods that use the naming convention of Page_event, such as Page_Load and Page_Init.
The AutoEventWireup attribute requires that the page event handlers have specific, predictable names.
If you want to create your own names for page event handlers, you can set AutoEventWireup to false and then bind the events to the methods explicitly.
If you include explicit binding, you must make sure that the AutoEventWireup is disabled so that the method is not called twice,
once automatically by AutoEventWireup and another time by your explicit binding.
For example, in Visual Basic, you can use the Handles keyword to perform the binding.
this.PreRender += new EventHandler(MyFunction_PreRender);
you will have to wire up your Page load manually -
this.Load += new EventHandler(Page_Load);
delete the Event Handler in Code Behind and generate new one
also set in page tag AutoEventWireUp="false"
May this solve your problem
Dec 19, 2009 05:36 AM|Gadiputi sudhir|LINK
Thank u ,its helped me a lot .
May 17, 2010 08:29 AM|sadarasmts|LINK
i have a accordian and contain a link button , when im click the button at the first time it wont work but click it again itll work what is the wrong with that
Jul 12, 2010 06:37 PM|xr280xr|LINK
I noticed today that button click event handlers are firing twice for me in some cases when the button is inside an UpdatePanel -- but only in Firefox. I'm wondering if this might have to do with the Firefox 18.104.22.168 update that came out today because I never
noticed this problem until today. Has anyone else run into this problem?
I have the same problem when debugging. I have a button inside an update panel that is firing the click event twice in firefox but not IE. My event handler calls Response.Redirect at the end to redirect to the next page, but in FireFox that doesn't work
because of the second click. I have AutoEventWireup = true and onclick="btnContinue_Click". I have no other event wireup coded in the codebehind. Without either of these two the event is not fired at all. I don't understand why onclick has to be set if AuotEventWireup
is true, but why the event is firing twice in this case also seems to be unanswered here.
Oct 19, 2010 02:42 AM|richin|LINK
this might help you out
private bool Ok2Delete(int bypassCount)
Session["delCount"] = Session["delCount"] == null ? 0 : Session["delCount"];
return !((int)(Session["delCount"] = (((int)Session["delCount"]) + 1) % bypassCount) == 0);
}just call it at the beginning of your RowDeleting event handling method. Example:
if (!Ok2Delete(2)) return; // parameter of 2 if event is firing twice
// 3 if trice, etc...
click event firing twice
Oct 19, 2010 08:30 AM|xr280xr|LINK
In firefox, the button click was triggering a postback so it was doing two postbacks.
Aug 17, 2011 06:46 PM|dmurphy7299|LINK
I had the same problem in asp.net/c#. Nothing worked per the blogs. I ended up deleting my whole project, downloading new code from TFS, and bingo, it worked. Apparently the Rebuild feature doesn't always clean itself up very well.
Aug 25, 2011 01:13 AM|AJV King|LINK
Thank for example, BUT I am building asp.net website. And here i have to specify the "onclick="button1_Click" else the event wont fire.
Please help me out.
Apr 21, 2014 01:07 PM|TheDirtyBird|LINK
iupchris10 is correct! I'm upgrading a asp.net 1.1 to asp.net 4.5. This fixed my issue.
Jul 29, 2015 12:05 PM|Ernesto Ono|LINK
I had the same problem and thank you for the solution, my project works very well !!!!