javascript - Onclientclick is not working for in asp button - Stack Overflow

Onclientclick is not working for me in asp button. The button is present inside update panel<asp:Upd

Onclientclick is not working for me in asp button. 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.

Onclientclick is not working for me in asp button. 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.

Share Improve this question edited Apr 26, 2016 at 7:08 Surendra Mourya asked Apr 26, 2016 at 6:51 Surendra MouryaSurendra Mourya 6113 gold badges10 silver badges33 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

I achieved this with the help of 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. 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745216228a4617037.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信