This tutorial for programmers will show you how to run JavaScript from code behind follow the next steps:

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition

1. Set the Body tag in your page/master page:

<body runat="server" id="MyBody">

2. Write the script tag in your page:

<script src="MyFunction.js" type="text/javascript"></script>

3. In the code behind attach the onload attribute to the body tag:

protected void Page_Load(object sender, EventArgs e)
MasterPageBodyTag = (HtmlGenericControl)Page.Master.FindControl(“MyBody”);
MasterPageBodyTag.Attributes.Add(“Onload”, “MyFunction()”);