Write your javascript function in head section of your page as you normally do,
<head>
<script type="text/javascript">
yourfunction()
{}
</script>
</head>
and then call it from codebehind like this:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", yourfunction(), false);