ASP.Net按钮单击 [英] ASP.Net Button click

查看:71
本文介绍了ASP.Net按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于asp.net页面中的按钮,我需要在第二次单击它以触发按钮单击事件。我相信某些设置可能不对。如何才能使单击发生事件?谢谢。

For a button in an asp.net page, I need to click it on the second time to fire the button click event. I believe that some settings may not be right. How can make only single click happen to fire the the event? Thanks.

推荐答案

这似乎是一个非常常见的问题,你的事件处理程序方法会运行两次。



它是由VS.NET插入 2事件处理程序的连接引起的:



- 一旦进入aspx(HTML)例如:< asp:button ... =onclick =btnTest_Clickxmlns:asp =#unknown/>



- 一旦进入VS.NET生成部分(InitializeComponent),例如:

this.btnTest.Click + = new System.EventHandler(this.btnTest_Click);



最简单的解决方案,即imo,只需删除OnClick ...HTML来自.aspx页面的标记。



例如更改:

< asp:button id =btnTest runat =servertext =Testonclick =btnTest_Clickxmlns:asp =#unknown/>



对此:

< asp:button id =btnTestrunat =servertext =Testxmlns:asp =#unknown/>



重建,宾果游戏! - 每次点击一次。



此处 [ ^ ]



-KR
This seems to be a very common problem where by your event handler method gets run twice.

It is caused by VS.NET inserting 2 wireup of the event handler:

- once in the aspx (HTML) eg: <asp:button ...="" onclick="btnTest_Click" xmlns:asp="#unknown" />

- and once in the VS.NET generated section (InitializeComponent) eg:
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);

The easiest solution, imo, is to simply remove the "OnClick..." HTML markup from the .aspx page.

Eg change this:
<asp:button id="btnTest" runat="server" text="Test" onclick="btnTest_Click" xmlns:asp="#unknown" />

To this:
<asp:button id="btnTest" runat="server" text="Test" xmlns:asp="#unknown" />

Rebuild, and bingo! - 1 event per click.

ripped from here[^]

-KR


请参阅我在2014年3月14日的评论:

问题可能是由于另一个控件(例如文本框)。无论出于何种原因,我必须在点击按钮之前点击一下。为了消除这个问题,我修改了运行textbox_TextChanged()的代码。然后,单击该按钮不再需要执行两次。感谢所有评论者。

感谢评论家,特别是。那些提供注释或解决方案。
See my comment on March 14, 2014:
The problem may be due to another control (e.g. a textbox). For whatever reason, I have to make a click before clicking the button. To eliminate this problem, I revised the code that runs textbox_TextChanged(). Then, clicking the button does not need to do twice any more. Thanks to all of the reviewers.
Thanks to Reviewers, esp. to those provided comments or solutions.


如果您使用ID变量而不进行初始化,这可能是错误的来源。
if you use ID variable without initialize, this maybe source of the mistake.


这篇关于ASP.Net按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆