开发者

HtmlButton handler fires twice when clicked (when AutoEventWireup="True")

I have an html button, see below. When it's clicked and AutoEventWireup="true", the Save_Click click handler is fired twice. When AutoEventWireup="False", it fires once.

Why is it firing twice? The button is not registered twice and no code which is adding the event handler. Using master page and no Ajax.

<button id="Save" accesskey="v" type="submit" 开发者_运维百科runat="server" onserverclick="Save_Click"></button>


And now (at least in .net 4) even better:

<button runat="server">

by default behaves as it has type="submit" (fires twice on click), so for it to work correctly, we should explicitly set type="button", i.e.:

<button id="ButtonSubscribe2" runat="server" type="button" onserverclick="Save_Click"></button>


Ok I found out that that an HTMLButton fires for the onserverclick event and for the type="submit". When I removed type="submit", it fires once. This quirky behavior took me a long time to discover!


Just a guess: the handler isn't being fired twice, but you've set up a similar behavior in the Page_Load event that makes it appear to be firing twice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜