简体   繁体   English

在asp按钮中onclientclick不起作用

[英]Onclientclick is not working for in asp button

Onclientclick is not working for me in asp button. 在ASP按钮中,onclientclick对我不起作用。 The button is present inside update panel 该按钮位于更新面板中

    <asp:UpdatePanel ID="UpLoad" runat="server">
<ContentTemplate>
     <asp:Button ID="btnProcess" runat="server" Text="Process" OnClientClick="alert('hi');" onClick="btnProcessing_Click" />
</ContentTemplate>
<Triggers>
    <asp:PostBackTrigger ControlID="btnProcess" />
</Triggers>

Can someone help me where am i going wrong. 有人可以帮我我在哪里错了。

I achieved this with the help of jquery. 我是在jquery的帮助下实现的。

 $('#<%=btnProcess.ClientID%>').click(function () {
        alert('hi');
    });

It worked. 有效。 Thanks all for your help 感谢你的帮助

  function validate() { //if validation sucess return true otherwise return false. if (document.getElementById("txtSample").value != "") { return true; } alert('Enter a value'); return false; } 
 <body> <form id="form1" runat="server"> <div> Enter a value:<asp:TextBox ID="txtSample" runat="server"></asp:TextBox><br /> <asp:Button ID="btnSubmit" runat="server" Text="Click Me" OnClientClick="javascript:return validate();" OnClick="btnSubmit_Click" /> </div> </form> </body> </html> In aspx page:: ============= protected void btnSubmit_Click(object sender, EventArgs e) { Response.Write("The textbox value is " + txtSample.Text); } 

You can use PostBackTrigger inside UpdatePanel to trigger both OnClick and OnClientClick events. 您可以在UpdatePanel使用PostBackTrigger来触发OnClickOnClientClick事件。 Here's how: 这是如何做:

<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
        <asp:Button ID="btnProcess" runat="server" Text="Process" OnClientClick="javascript:alert('hi');" onClick="btnProcess_Click" />
    </ContentTemplate>
<Triggers>
   <asp:PostBackTrigger ControlID="btnProcess" />
</Triggers>
 </asp:UpdatePanel>

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

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