简体   繁体   English

按钮未在 ASP.NET Webforms 中触发

[英]Button is not triggering in ASP.NET Webforms

I'm trying to fix a bug I've encountered with a button not triggering in my webform.我正在尝试修复我遇到的一个错误,我的网络表单中没有触发按钮。

The code for the button in the aspx file and the vb file looks like this: aspx 文件和 vb 文件中按钮的代码如下所示:

<asp:Button ID="btnUserEditSave" runat="server" Text="Save User" ClientIDMode="Static" CssClass="button saveButton xbtnWaitEvent" width="100px" ToolTip="Save changes" />

Protected Sub btnUserEditSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUserEditSave.Click

I haven't included to code for the button itself as it's irrelevant because the bug relates to the button not triggering rather than the code of the button itself breaking.我没有包含按钮本身的代码,因为它无关紧要,因为该错误与按钮未触发有关,而不是按钮本身的代码损坏。 I've tested how the button works and what causes it to not trigger and here's the information I have thus far:我已经测试了按钮的工作原理以及导致它不触发的原因,这是我目前掌握的信息:

When first saving user details through this button, the button triggers and all code runs as expected.当第一次通过此按钮保存用户详细信息时,按钮会触发并且所有代码按预期运行。 The page is the reloaded with the new user details showing.该页面将重新加载并显示新用户的详细信息。

However after doing this, the button will not trigger properly and when clicked will cause the page to go blank.但是,这样做后,按钮将无法正确触发,单击时将导致页面变为空白。 This is despite the fact that no page load methods written in the source trigger either nor does the Javascript seem to either which I've tried testing through the use of alerts (see code below):尽管事实上没有在源触发器中编写的页面加载方法也没有 Javascript 似乎我已经尝试通过使用警报进行测试(请参阅下面的代码):

if(document.getElementById('btnUserEditSave').clicked == true)
        {
           alert("button was clicked");
        }

It is worth noting that the other buttons on the page also do not work again in a very similar way.值得注意的是,页面上的其他按钮也不会以非常相似的方式再次工作。 The code behind the button does not trigger nor does a page load method trigger.按钮背后的代码不会触发,也不会触发页面加载方法。 But a blank page is still shown.但仍然显示空白页面。

If any further code is needed for context then I will provide as much as I can, and any help as to what might be causing this error would be greatly appreciated as I am rather stuck for ideas.如果上下文需要任何进一步的代码,那么我将尽可能多地提供,并且对于可能导致此错误的原因的任何帮助将不胜感激,因为我对想法感到困惑。 Thanks.谢谢。

您需要在 html 标记中添加 onclick 事件,这就是您连接它的方式。

 <asp:Button ID="btnUserEditSave" onclick="btnUserEditSave_Click" runat="server" Text="Save User" ClientIDMode="Static" CssClass="button saveButton xbtnWaitEvent" width="100px" ToolTip="Save changes" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM