RadControls for ASP.NET AJAX Telerik RadAjax offers the ability to execute custom JavaScript code which comes as a response from the server thus giving you more flexibility to complete more specific or complex tasks on the client.
The best and most intuitive approach is to use the ResponseScripts property of the RadAjaxPanel or RadAjaxManager.
Here is a source code example which pops an alert when a Button is clicked:
CopyC#
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()));
}
CopyVB.NET
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
RadAjaxManager1.ResponseScripts.Add(String.Format(, DateTime.Now.ToLongTimeString()))
End SubAnother approach, however, is to use the RegisterStartupScript static method of the ScriptManager class:
CopyC#
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);
}
CopyVB.NET
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim script As String = String.Format(, DateTime.Now.ToLongTimeString())
ScriptManager.RegisterStartupScript(Page, GetType(Page), "myscript", script, True)
End SubYou can also use the pageLoaded event of the PageRequestManager class.