OnClick事件在ASP.NET页中不起作用 [英] OnClick events not working in ASP.NET page
问题描述
我有一个从母版页继承的aspx页. 在主页上,我有一个按钮,对于解决方案中的每个页面都是通用的.
I am having a aspx page which inherits from a master page. In the master page I have a button that is common for every page in the solution.
<div class="btn_general_mid">
<asp:Button
ID="btnMainSearch"
ValidationGroup="MainSearch"
OnClientClick="CheckSearchTextBox()"
CausesValidation="true"
runat="server"
OnClick="btnMainSearch_Click"
CssClass="search_btn_submit"
Text="Search" />
</div>
CheckSearchTextBox()
是javascript函数,btnMainSearch_Click
是正在处理按钮部分后面代码的事件.
Here the CheckSearchTextBox()
is a javascript function and the btnMainSearch_Click
is the event which is handling the code behind part of the button.
在特定页面中,不会触发该按钮单击事件btnMainSearch_Click
. (调试器无法达到代码中的要求)
In a certain page this button click event btnMainSearch_Click
is not fired. (The debugger does not reach that in the code)
在运行时,(使用Firebug进行检查时)这是为按钮生成的代码段.
In the runtime, (When examined using Firebug) this is the code segment generated for the button.
<div class="btn_general_mid">
<input id="ctl00_btnMainSearch"
class="search_btn_submit"
type="submit"
onclick="CheckSearchTextBox();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$btnMainSearch", "", true, "MainSearch", "", false, false))"
value="Search"
name="ctl00$btnMainSearch"></div>
实际上,在此按钮可以正常工作的其他页面中,为该按钮生成了相同的html输出.我在这里想念东西吗?
Actually in the other pages where this button works fine , the same html output is generated for this button. Am I missing something here?
推荐答案
检查是否存在验证错误,因为它不允许触发服务器端事件btnMainSearch_Click
.
Check whether there are any validation errors because it would not allow server side event btnMainSearch_Click
getting fired.
这篇关于OnClick事件在ASP.NET页中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!