简体   繁体   English

ASP.NET按钮的onclick事件未触发服务器端代码

[英]Asp.net button onclick event is not firing serverside code

This has been discussed too many times already, but none of those threads helped me. 已经讨论了太多次了,但是这些线程都没有帮助我。

Below is .aspx code. 下面是.aspx代码。

<div id="Panel_login" runat="server" class="panel-default">
     <asp:UpdatePanel ID="UpdatePanel_login"  UpdateMode="Conditional" runat="server">
        <ContentTemplate>
             <asp:RequiredFieldValidator ID="txtb_loginEmailRequiredFieldValidator" ControlToValidate="txtb_loginEmail" runat="server" ErrorMessage="Email can't be Empty"></asp:RequiredFieldValidator>
             <asp:TextBox ID="txtb_loginEmail" CssClass="form-control" placeholder="Your Email" runat="server" TextMode="Email" Width="400px"></asp:TextBox>
             <asp:RequiredFieldValidator ID="txtb_loginPasswordRequiredFieldValidator" ControlToValidate="txtb_loginPassword" runat="server" ErrorMessage="Password can't be Empty"></asp:RequiredFieldValidator>                                        
             <asp:TextBox ID="txtb_loginPassword" CssClass="form-control" TextMode="Password" placeholder="Password" runat="server" Width="400px"></asp:TextBox>
             <asp:Button ID="btn_userlogin" runat="server" OnClick="loginUser" Text="Login" />                             
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

Below is my .cs file code. 以下是我的.cs文件代码。

 protected void loginUser(object sender, EventArgs e)
 {
     Response.Redirect("www.google.com");
     log.Debug("login_user is called");    
 }

On click of button, it should fire event, but it is not happening. 单击按钮时,它应该触发事件,但是没有发生。

I have tried adding triggers to Update Panel for this button click, still didnt work. 我曾尝试将触发器添加到“更新面板”中以实现此按钮单击,但仍然无法正常工作。

It only gets fired when another button on same page is fired previously. 仅在先前触发同一页面上的另一个按钮时才会触发。

Can someone suggests what I am missing here. 有人可以建议我在这里缺少什么吗?

Thanks for help. 感谢帮助。

I have seen the event never getting wired up. 我见过该活动从未被安排。 Try... 尝试...

(1) In design mode delete the button, drag a new one back on the design surface, then rename your button. (1)在设计模式下,删除按钮,将一个新的按钮拖回设计图面上,然后重命名按钮。 OR 要么

(2) Go into design view, click the button, then properties, look at the Lightening Bolt Icon (event) remove that event, save, and add it back and save. (2)进入设计视图,单击按钮,然后单击属性,查看“闪电螺栓”图标(事件),删除该事件,保存,并将其添加回并保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM