OnClick events not working in ASP.NET page

只愿长相守 提交于 2020-01-01 07:22:44

问题


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>

Here the CheckSearchTextBox() is a javascript function and the btnMainSearch_Click is the event which is handling the code behind part of the button.

In a certain page this button click event btnMainSearch_Click is not fired. (The debugger does not reach that in the code)

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>

Actually in the other pages where this button works fine , the same html output is generated for this button. Am I missing something here?


回答1:


Check whether there are any validation errors because it would not allow server side event btnMainSearch_Click getting fired.




回答2:


One reason for this is may be that postback is being stopped by some visible or apparently invisible validator. Try adding cause validation to false in button tag.

CausesValidation="false"


来源:https://stackoverflow.com/questions/27038297/onclick-events-not-working-in-asp-net-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!