Reputation: 611
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.
Upvotes: 0
Views: 12004
Reputation: 611
I achieved this with the help of jquery.
$('#<%=btnProcess.ClientID%>').click(function () {
alert('hi');
});
It worked. Thanks all for your help
Upvotes: 2
Reputation: 1197
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>
Upvotes: 0
Reputation: 106
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);
}
Upvotes: 0