ASP.NET按钮不点击点击事件 [英] ASP.NET button not firing on click event
问题描述
udemy
的页眉和页脚放在母版页
中。但是当我将一个按钮添加到m个Web表单之一时,点击事件将不会触发。 < asp:Button ID = Button1runat =serveronclick =Button1_Click1Text =Button/>
protected void Button1_Click1(object sender,EventArgs e)
{
Page.Title =Sample Text;
}
要解决此问题,我从我的网页中删除了所有脚本。另外我试图将 CausesValidation
设置为False。但没有帮助。
你能帮我解决这个问题吗?
更新
我将OnClick活动添加到我的码。但是我仍然面临这个问题。
所有以前的答案都是正确的,除了已经添加了OnClick事件
.aspx文件。
我不知道这是否在您正在使用的模板中,或代码中的其他位置。但是,我建议您检查以下内容(根据我遇到的类似情况):
- 您是否有任何现场验证器在你的.aspx页面?也许其中一个验证器被触发,如果没有任何错误消息。
- 您是否从其他地方复制了该按钮?如果是,则尝试添加一个新按钮并添加其点击事件,双击设计模式中的按钮。有时OnClick按钮的事件未在.designer.cs文件中注册。
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";
}
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?
Update
I added the OnClick event to my code. But I still face that problem.
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):
- Do you have any Field Validators in your ".aspx" page? Perhaps one of those validators are fired and if they were without any Error Messages.
- Have you copied that button from somewhere else? If yes, then try to add a new button and add its click event, by double clicking the button in the design mode. As sometimes the "OnClick" button's event is not registered on the ".designer.cs" file.
这篇关于ASP.NET按钮不点击点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!