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);
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.