In this article I will explain with an example, how to call JavaScript function from Code Behind (Server Side) when using ASP.Net AJAX UpdatePanel.
The ClientScript.RegisterClientScriptBlock and ClientScript.RegisterStartupScript functions do not work during Partial PostBack when ASP.Net AJAX UpdatePanel is used and hence ScriptManager’s RegisterClientScriptBlock and RegisterStartupScript method is used to call JavaScript function.
 
 
HTML Markup
The HTML Markup consists of ASP.Net AJAX Script Manager Control, an UpdatePanel and a Button which when clicked will show a JavaScript Alert Message Box.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
    <asp:Button Text="Show Message" runat="server" OnClick="ShowMessage" />
</ContentTemplate>
</asp:UpdatePanel>
 
 
Code Behind
Inside the Button Click event handler, I have made use of  ScriptManager.RegisterClientScriptBlock methods to register a JavaScript alert message box.
C#
protected void ShowMessage(object sender, EventArgs e)
{
    string message = "alert('Hello! Mudassar.')";
    ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
}
 
VB.Net
Protected Sub ShowMessage(sender As Object, e As EventArgs)
    Dim message As String = "alert('Hello! Mudassar.')"
    ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
End Sub
 
ASP.Net AJAX UpdatePanel: Call JavaScript function from Code Behind (Server Side)
 
Demo
 
Downloads