Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call a JavaScript function in the OnClick event. Is it possible bellow :
The buttton's source code.

<asp:Button ID="btnMachinaryType" runat="server" Font-Bold="True" Font-Italic="True "Width="180px" Text="Create New Machine Type" onclick="btnMachinaryType_Click" />
Posted
Comments
bbirajdar 21-Mar-13 7:07am    
call javascript in the OnClientClick event

For an ASP.Net button, OnClick refers to the server side event, the C# event. If you want to run JavaScript use the OnClientClick event. Note: Javascript will run first. If you return false, for example, you can prevent the button from posting back and running the C#.

Both OnClientClick and OnClick can be used.
 
Share this answer
 
Comments
fjdiewornncalwe 21-Mar-13 14:37pm    
My 5.
<title>Untitled Page


function fnTest()
{
if(document.getElementById('txtName').value == '')
{
document.getElementById('txtName').focus();
alert('Please Enter Value');
return false;

}
else return true;
}







<asp:textbox id="txtName" runat="server" xmlns:asp="#unknown">
<asp:button id="btnMachinaryType" runat="server" font-bold="True" font-italic="True " xmlns:asp="#unknown">
OnClientClick="return fnTest()" Width="180px" Text="Create New Machine Type" OnClick="btnMachinaryType_Click" />



 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900