ASP.NET 按钮不会在单击事件时触发 [英] ASP.NET button not firing on click event

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

问题描述

我是 Asp.net 的新手,我的问题可能不太专业.我在我的 asp.net web 表单项目中使用了 Udemy.com 的设计.我将 udemy 的页眉和页脚放在 masterpage 中.但是当我向其中一个网页表单添加一个按钮时,点击事件不会触发.

I am new to Asp.net and my question may not be so professional. I am using the design of Udemy.com in my asp.net web forms project. I put the header and footer of udemy in a masterpage. But when I add a button to one of m web forms the click event will not fire.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="Button" />

protected void Button1_Click1(object sender, EventArgs e)
{
    Page.Title = "Sample Text";
}

为了解决这个问题,我从我的页面中删除了所有脚本.我还尝试将 CausesValidation 设置为 False.但没有任何帮助.你能帮我解决这个问题吗?

To fix this problem, I deleted all of the scripts from my pages. Also I tried to set CausesValidation to False. But nothing helps. Could you help me fix this problem?

我在代码中添加了 OnClick 事件.但我仍然面临这个问题.

I added the OnClick event to my code. But I still face that problem.

推荐答案

之前的所有答案都是正确的,除了您已经添加"了 OnClick 事件到.aspx"文件.我不知道它是您使用的模板中的内容,还是代码中的其他地方.但我建议您检查以下内容(根据我陷入类似情况的经验):

All the previous answers are correct, except that you "already added" the OnClick event to the ".aspx" file. I don't know whether it is something in the template you're using, or somewhere else in the code. But I would recommend that you check the following (Based on my experience in being stuck in similar situations):

  1. 您的.aspx"页面中是否有任何字段验证器?也许其中一个验证器被解雇了,如果他们没有任何错误消息.
  2. 您是否从其他地方复制了该按钮?如果是,则尝试添加一个新按钮并添加其单击事件,方法是在设计模式下双击该按钮.因为有时OnClick"按钮的事件未在.designer.cs"文件中注册.

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

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