New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Create Alert on server-side using RadWindowManager without rasing the Page_Load event

Environment

ProductRadWindowManager for ASP.NET AJAX
LanguageC#, VB, JavaScript

Description

Creating an alert on the server-side is usually done by calling the RadWindowManager1.RadAlert() method on server-side

C#
private void RadButton1_Click(object sender, EventArgs e)
{
	RadWindowManager1.RadAlert();
}

However, this approach will raise the Page_Load event. In some cases, there might be a specific logic in the Page Load event, which, if executed twice may produce a different outcome.

Solution

Instead of calling the Server-Side "RadAlert()", register the Client-Side "radalert()" method as a StartupScript.

Make sure to have a RadWindowManager on the Page. The Server-Side "RadAlert()" and Client-Side "radalert()" methods are part of the RadWindowManager APIs.

XML
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>

Register the StartupScript in the Button Click

C#
private void RadButton1_Click(object sender, EventArgs e)
{
    string script = @"function myFunction() {
						Sys.Application.remove_load(myFunction);
						var oAlert = radalert('Alert Message', null, null, 'Window Title', AlertCallBackFn, null);
					};
					Sys.Application.add_load(myFunction);";

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "name", script, true);
}

The CallBack function if defined in the StartUpScript

JavaScript
function AlertCallBackFn(arg) {
	/* Optional: Alert again to display the radalert() callback response */
    radalert("This is the CallBack response from the RadAlert.");
}
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support