本文介绍了提交按钮单击事件不会首次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 是。我已经完成了所有类似的问题。是的,以及所有Google链接。 不,没有javascript或其他客户方面的事情发生。 不,没有更新面板。 但Button不会触发Click事件,除非该页面已经提交过一次。甚至没有推送提交按钮...甚至取消按钮,它只会重新加载页面,使提交按钮工作。 所有可能的组合已尝试过UseSubmitBehavior和CausesValidation属性。 我正在寻找一个异常原因,而不是经常看到的原因。 我甚至创建了一个新页面。剥离一切到准系统无所事事,它仍然无法工作。 这是ASPX代码: < html xmlns = http ://www.w3.org/1999/xhtml > < head runat = 服务器 > < title > 问题< / title > < link rel = stylesheet type = text / css href = PatientRounding.css / > < / head > < body > < 表格 id = form1 runat = 服务器 > < div > < asp:标签 ID = lblCount runat = 服务器 文本 = 已添加回复 > < / asp:标签 > < / div > < asp:Panel runat = server id = divQuestions CssClass = MainDiv > < / asp:Panel > < div > < asp:按钮 ID = btnQuit runat = 服务器 CssClass = PageButton OnClick = btnQuit_Click 文字 = 返回开始 / > < asp:按钮 ID = btnCancel runat = server CssClass = PageButton OnClick = btnCancel_Click 文字 = 清除答案 / > < asp:按钮 ID = btnSubmit runat = server CssClass = PageButton OnClick = btnSubmit_Click 文字 = 提交答案 / > < / div > < / form > < / body > < / html > 这是aspx.cs代码: public partial class PatientQuestions:System.Web.UI.Page { protected void Page_Load( object sender,EventArgs e) { } protected void Page_PreInit( object sender,EventArgs e) { } protected void btnSubmit_Click( object sender,EventArgs e) { lblCount.Text = 完成; } protected void btnCancel_Click( object sender,EventArgs e) { } protected void btnQuit_Click( object sender,EventArgs e) { Server。转移( Default.aspx, false ); } } 我没看到什么?为什么我必须在代码隐藏代码之前重新加载页面? 无论我是在VS桌面上使用IISExpress在桌面上运行,还是在外面运行网络服务器。 可能导致这种情况的原因是什么?解决方案 已修复。 我从来没有找到导致它的原因。 我会在页面以外的地方假设一些剩余的垃圾文件。尽管做了干净并删除了选项文件等,它仍然无法工作。 我创建了一个新项目,然后复制了所有代码糟糕的项目......它的工作正常。 我需要退休。很快。 Yes. I've gone through all the similar questions here and at SO. Yes, and all the Google links.No, there's no javascript or other client side things going on.No, there's no update panel.But the Button does not fire the Click event unless the page has already been submitted once. Not even that the Submit button has been pushed...even the Cancel button, which does nothing but reload the page, makes the Submit button work.All possible combinations of the UseSubmitBehavior and CausesValidation properties have been tried.I'm looking for an abnormal cause, not an often-seen one.I even created a new page. stripped everything down to barebones do-nothing and it STILL doesn't work.Here's the ASPX code:<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Questions</title> <link rel="stylesheet" type="text/css" href="PatientRounding.css" /></head><body> <form id="form1" runat="server"> <div> <asp:Label ID="lblCount" runat="server" Text=" responses added"></asp:Label> </div> <asp:Panel runat="server" id="divQuestions" CssClass="MainDiv" > </asp:Panel> <div> <asp:Button ID="btnQuit" runat="server" CssClass="PageButton" OnClick="btnQuit_Click" Text="Return to Start" /> <asp:Button ID="btnCancel" runat="server" CssClass="PageButton" OnClick="btnCancel_Click" Text="Clear Answers" /> <asp:Button ID="btnSubmit" runat="server" CssClass="PageButton" OnClick="btnSubmit_Click" Text="Submit Answers" /> </div> </form></body></html>Here's the aspx.cs code:public partial class PatientQuestions : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Page_PreInit(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { lblCount.Text = "Done"; } protected void btnCancel_Click(object sender, EventArgs e) { } protected void btnQuit_Click(object sender, EventArgs e) { Server.Transfer("Default.aspx", false); } }What am I not seeing? Why do I have to reload the page before the code behind code works?This happens whether I'm running on my desktop with IISExpress from within VS, or out on the web server.What could possibly cause this? 解决方案 Fixed.I never did find what was causing it.I'm going to assume some leftover gunk somewhere other than the page files. Despite doing a "clean" and deleting the options file and such, it still wouldn't work.I created a new project, then copied over all the code from the bad project...and it works just fine.I need to retire. Soon. 这篇关于提交按钮单击事件不会首次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 23:06