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 badges3 Answers
Reset to default 2I 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条)