asp.net按钮OnClick事件未触发

时间:2022-02-25 20:08:33

I have problem in asp.net button control.

我在asp.net按钮控件中有问题。

I define a button in form, onclick event of button is not firing when I click on the button.

我在窗体中定义了一个按钮,当我点击按钮时按钮的onclick事件没有触发。

<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" /> 

protected void btn_QuaSave_Click(object sender, EventArgs e)
{

}

13 个解决方案

#1


10  

Have you copied this method from other page/application ? if yes then it will not work, So you need to delete the event and event name assigned to the button then go to design and go to button even properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button. this should work

您是否从其他页面/应用程序复制了此方法?如果是,那么它将无法工作,所以你需要删除分配给按钮的事件和事件名称然后转到设计并转到按钮甚至属性转到onClick事件双击它旁边,它将生成事件并自动分配事件名称到按钮。这应该工作

#2


7  

Because your button is in control it could be that there is a validation from another control that don't allow the button to submit. The result in my case was to add CausesValidation property to the button:

因为您的按钮处于控制状态,所以可能是另一个控件的验证不允许按钮提交。我的结果是将CausesValidation属性添加到按钮:

<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" CausesValidation="False"/> 

#3


6  

If you are using updatepanel on onclick event, this may happen.

如果您在onclick事件上使用updatepanel,则可能会发生这种情况。

Use 'EnableEventValidation="false"' in your page markup like this :

在页面标记中使用'EnableEventValidation =“false”',如下所示:

<%@ Page Language="C#" MasterPageFile="~/ars_home.master" AutoEventWireup="true" CodeFile="Transaction_Window.aspx.cs" Inherits="Transaction_Window" EnableEventValidation="false" %>

Hope this helps

希望这可以帮助

#4


4  

I had the same problem, my aspnet button's click was not firing. It turns out that some where on other part of the page has an input with html "required" attribute on.

我有同样的问题,我的aspnet按钮的点击没有激发。事实证明,在页面的其他部分有一些输入具有html“required”属性。

This might be sound strange, but once I remove the required attribute, the button just works normally.

这可能听起来很奇怪,但是一旦我删除了必需的属性,按钮就会正常工作。

#5


2  

In my case I put required="required" inside CKEditor control.
Removing this attribute fixed the issue.
Before

在我的情况下,我在CKEditor控件中放置required =“required”。删除此属性可解决此问题。之前

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server" required="required"></CKEditor:CKEditorControl>

After

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>

#6


1  

Try to Clean your solution and then try once again.

尝试清理您的解决方案,然后再试一次。

It will definitely work. Because every thing in code seems to be ok.

它肯定会奏效。因为代码中的每件事似乎都没问题。

Go through this link for cleaning solution>

浏览此链接以获取清洁解决方案>

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/

#7


1  

Try to go into Design mode in Visual Studio, locate the button and double click the button that should setup the event. Otherwise once the button is selected in Design more, go to the properties and try setting it from there.

尝试在Visual Studio中进入设计模式,找到按钮并双击应设置事件的按钮。否则,在“设计更多”中选择按钮后,转到属性并尝试从那里进行设置。

#8


1  

Add validation groups for your validator elements. This allows you distinguish between different groups which to include in validation. Add validation group also to your submit button

为验证器元素添加验证组。这允许您区分要包含在验证中的不同组。将验证组也添加到您的提交按钮

#9


1  

in my case: make sure not exist any form element in your page other than top main form, this cause events not fired

在我的情况下:确保页面中除了顶部主窗体之外不存在任何表单元素,这会导致事件未触发

#10


0  

If it's throwing no error but still not firing the click event when you click the submit button, try to add action="YourPage.aspx" to your form.

如果单击提交按钮时没有抛出任何错误但仍未触发click事件,请尝试将action =“YourPage.aspx”添加到表单中。

#11


0  

i had the same problem did all changed the button and all above mentioned methods then I did a simple thing I was using two forms on a single page and form with in the form so I removed one and it worked :)

我有同样的问题,所有改变按钮和所有上述方法,然后我做了一个简单的事情,我在单个页面上使用两个表单和表单中的表单,所以我删除了一个,它工作:)

#12


0  

If the asp button is inside <a href="#"> </a> tag then also the Click event will not raise.

如果asp按钮位于 标记内,则Click事件也不会引发。

Hope it's useful to some one.

希望它对某些人有用。

#13


0  

I had a similar issue and none of the answers worked for me. Maybe someone finds my solution helpful. In case you do not mind submitting on button click, only attaching to click event setting UseSubmitBehavior="false" may be worth trying.

我有一个类似的问题,没有一个答案对我有用。也许有人发现我的解决方案有帮如果你不介意按钮点击提交,只有附加到点击事件设置UseSubmitBehavior =“false”可能值得尝试。

#1


10  

Have you copied this method from other page/application ? if yes then it will not work, So you need to delete the event and event name assigned to the button then go to design and go to button even properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button. this should work

您是否从其他页面/应用程序复制了此方法?如果是,那么它将无法工作,所以你需要删除分配给按钮的事件和事件名称然后转到设计并转到按钮甚至属性转到onClick事件双击它旁边,它将生成事件并自动分配事件名称到按钮。这应该工作

#2


7  

Because your button is in control it could be that there is a validation from another control that don't allow the button to submit. The result in my case was to add CausesValidation property to the button:

因为您的按钮处于控制状态,所以可能是另一个控件的验证不允许按钮提交。我的结果是将CausesValidation属性添加到按钮:

<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" CausesValidation="False"/> 

#3


6  

If you are using updatepanel on onclick event, this may happen.

如果您在onclick事件上使用updatepanel,则可能会发生这种情况。

Use 'EnableEventValidation="false"' in your page markup like this :

在页面标记中使用'EnableEventValidation =“false”',如下所示:

<%@ Page Language="C#" MasterPageFile="~/ars_home.master" AutoEventWireup="true" CodeFile="Transaction_Window.aspx.cs" Inherits="Transaction_Window" EnableEventValidation="false" %>

Hope this helps

希望这可以帮助

#4


4  

I had the same problem, my aspnet button's click was not firing. It turns out that some where on other part of the page has an input with html "required" attribute on.

我有同样的问题,我的aspnet按钮的点击没有激发。事实证明,在页面的其他部分有一些输入具有html“required”属性。

This might be sound strange, but once I remove the required attribute, the button just works normally.

这可能听起来很奇怪,但是一旦我删除了必需的属性,按钮就会正常工作。

#5


2  

In my case I put required="required" inside CKEditor control.
Removing this attribute fixed the issue.
Before

在我的情况下,我在CKEditor控件中放置required =“required”。删除此属性可解决此问题。之前

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server" required="required"></CKEditor:CKEditorControl>

After

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>

#6


1  

Try to Clean your solution and then try once again.

尝试清理您的解决方案,然后再试一次。

It will definitely work. Because every thing in code seems to be ok.

它肯定会奏效。因为代码中的每件事似乎都没问题。

Go through this link for cleaning solution>

浏览此链接以获取清洁解决方案>

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/

#7


1  

Try to go into Design mode in Visual Studio, locate the button and double click the button that should setup the event. Otherwise once the button is selected in Design more, go to the properties and try setting it from there.

尝试在Visual Studio中进入设计模式,找到按钮并双击应设置事件的按钮。否则,在“设计更多”中选择按钮后,转到属性并尝试从那里进行设置。

#8


1  

Add validation groups for your validator elements. This allows you distinguish between different groups which to include in validation. Add validation group also to your submit button

为验证器元素添加验证组。这允许您区分要包含在验证中的不同组。将验证组也添加到您的提交按钮

#9


1  

in my case: make sure not exist any form element in your page other than top main form, this cause events not fired

在我的情况下:确保页面中除了顶部主窗体之外不存在任何表单元素,这会导致事件未触发

#10


0  

If it's throwing no error but still not firing the click event when you click the submit button, try to add action="YourPage.aspx" to your form.

如果单击提交按钮时没有抛出任何错误但仍未触发click事件,请尝试将action =“YourPage.aspx”添加到表单中。

#11


0  

i had the same problem did all changed the button and all above mentioned methods then I did a simple thing I was using two forms on a single page and form with in the form so I removed one and it worked :)

我有同样的问题,所有改变按钮和所有上述方法,然后我做了一个简单的事情,我在单个页面上使用两个表单和表单中的表单,所以我删除了一个,它工作:)

#12


0  

If the asp button is inside <a href="#"> </a> tag then also the Click event will not raise.

如果asp按钮位于 标记内,则Click事件也不会引发。

Hope it's useful to some one.

希望它对某些人有用。

#13


0  

I had a similar issue and none of the answers worked for me. Maybe someone finds my solution helpful. In case you do not mind submitting on button click, only attaching to click event setting UseSubmitBehavior="false" may be worth trying.

我有一个类似的问题,没有一个答案对我有用。也许有人发现我的解决方案有帮如果你不介意按钮点击提交,只有附加到点击事件设置UseSubmitBehavior =“false”可能值得尝试。