I will try to provide an example that I just created as a testing application.
Firstly, I used the ScriptManager to apply all the javascript files that I like to be present for the web page as follows:
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/JS/tester.js" />
</Scripts>
</asp:ScriptManager>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Call database" />
</div>
</form>
</body>
In the <Scripts>
tag add more of your JS files. This will ensure that your javascript file is added when you load the webpage.
The code that is there in my tester.js is:
function alertbox(data) {
alert("Completed the database operation with following data = " + data);
}
Now coming to your code behind scenario, what I have in my sample data is, I created a button on the webpage that would do some database operations and once completed it will alert the user about the sql update.
The button event handler is as follows:
protected void Button1_Click(object sender, EventArgs e)
{
Thread.Sleep(2000);
int sqlReturnValue = ExecuteTheQuery();
ScriptManager.RegisterStartupScript(this, typeof(string), "Database Completed", "alertbox(" + sqlReturnValue + ");", true);
}
Now this will call the Javascript function alertbox.
(Note: this is just a small example of how you can achieve the thing that you expect)
Update:
The same can be achieved with ClientScript as well.
What I did is, add a script tag:
<head runat="server">
<title>Test Page</title>
<script src="JS/tester.js" type="text/javascript"></script>
</head>
In the code behind of the button click:
protected void Button1_Click(object sender, EventArgs e)
{
Thread.Sleep(2000);
ClientScript.RegisterStartupScript(this.GetType(), "Database Completed", "alertbox(23);", true);
}
For understanding ClientScript and ScriptManager, check this question.