Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 2.92 KB

executing-custom-javascript-code-after-ajax-update.md

File metadata and controls

76 lines (56 loc) · 2.92 KB
title page_title description slug previous_url tags published type category res_type
Execute Custom Javascript Code after an AJAX Update
Execute Custom Javascript Code after AJAX Update
Learn how to execute custom JavaScript code after an Ajax update in Telerik UI for ASP.NET AJAX.
ajaxmanager/how-to/executing-custom-javascript-code-after-ajax-update
ajax/how-to/executing-custom-javascript-code-after-ajax-update, controls/ajaxmanager/how-to/executing-custom-javascript-code-after-ajax-update
telerik, asp, net, ajax, manager, execute, custom, javascript, code, after, update
true
how-to
knowledge-base
kb

Environment

Product Progress® Telerik® UI for ASP.NET AJAX

Description

How can I execute custom JavaScript code after an Ajax update in Telerik UI for ASP.NET AJAX?

Solution

Telerik UI for ASP.NET AJAX enables you to execute custom JavaScript code that comes as a response from the server thus giving you more flexibility to complete more specific or complex tasks on the client.

To execute custom JavaScript code after an AJAX update use any of the suggested approaches in this section.

The recommended and most intuitive approach is to use the [ResponseScripts]({% slug ajaxmanager/server-side-programming/properties %}) property of the AjaxPanel or AjaxManager.

The following example shows how to pop an alert when a Button is clicked.

protected void Button1_Click(object sender, System.EventArgs e)
	{
	    RadAjaxManager1.ResponseScripts.Add(string.Format("alert('Hello from the server! Server time is {0}');", DateTime.Now.ToLongTimeString()));
	}
	
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
	RadAjaxManager1.ResponseScripts.Add(String.Format("alert('Hello from the server! Server time is {0}');", DateTime.Now.ToLongTimeString()))
End Sub

The following example shows another approach—you can use the RegisterStartupScript static method of the ScriptManager class.

protected void Button1_Click(object sender, EventArgs e)
	{
	    string script = string.Format("alert('Hello from the server! Server time is {0}');", DateTime.Now.ToLongTimeString());
	    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
	}  
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
	Dim script As String = String.Format("alert('Hello from the server! Server time is {0}');", DateTime.Now.ToLongTimeString())
	ScriptManager.RegisterStartupScript(Page, GetType(Page), "myscript", script, True)
End Sub

Alternatively, you can use the pageLoaded event of the PageRequestManager class.

See Also

  • [Server-Side Properties of the AjaxManager]({%slug ajaxmanager/server-side-programming/properties%})