You can give these a try
register client script block inject after view state
register startup script inject before end of tag
1
ScriptManager.RegisterClientScriptBlock(Page, GetType(String), "myScriptName" + key, $"yourJsFunctionName({jsObject})", True)
2
ClientScript.RegisterStartupScript(GetType(),"hwa","alert('Hello World');",true);
3
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "Func()", true);
4 Another trick you can try
<body>
<head runat="server">
<script type="text/javascript">
function showAlertBox() {
alert("Invoked from codebehind.");
}
</script>
</head>
<form id="form1" runat="server">
<div>
<asp:Label ID="lable1" runat="server" Text=""></asp:Label>
<asp:Button ID="btnShow" runat="server" Text="Invoke Dialogue" />
</div>
</form>
</body>
Code behind to trigger the JavaScript function is here.
lable1.Text = "<script type='text/javascript'>showDialogue();</script>";
One more thing try to put alet('Test'); in your js function, it might be calling the function but not able to find your selector.