Some useful UpdatePanel extensions
I want to share some pretty basic and useful UpdatePanel control extensions with you. Method names are self explaining so I will not go deep in details.
public static void AlertOnLoad(this UpdatePanel updatePanel, string key, string message) { message = message.Replace("'", "\'").Replace("\r\n", "").Replace("\n", ""); message = "alert('" + message + "');"; AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, message, true); } public static void RedirectOnLoad(this UpdatePanel updatePanel, string key, string url) { url = "top.location.href = '" + url + "';"; AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, url, true); } public static void OpenWindowOnLoad(this UpdatePanel updatePanel, string key, string url) { url = "window.open('" + url + "');"; AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, url, true); }