I am using AJAX in asp:net and am trying to handle a situation where an asp:button triggers both a javascript method and a codebehind c# method. To do this I am using onclic
If you simply want to run your OnClientClick (client) code before your OnClick (server) code, try the following:
ASP.NET
<asp:Button ID="btn_mybutton" runat="server" Text="MyButton" OnClientClick="return JSFunction();" OnClick="CFunction"/>
Javascript
<script type="text/javascript">
function JSFunction() {
alert('Some JavaScript stuff');
return true;
}
</script>
C#
protected void CFunction(object sender, EventArgs e)
{
// Some server code
}
The JavaScript function is executed first and returned from before the server code is executed.