I'm trying to encapsulate the RadWindow in a global, static method so I can display messages, alerts and errors from anywhere in my web app. I have a MasterPage which sort of complicates things. I'm sure I'm not the first to try to create a univeral DisplayMessage radalert, can anyone share how they've handled this? I'm trying to figure out how to make it more dynamic in terms of templating from within the static method, or maybe even a better way to do this. Also it it a good idea to put a RadWindowManager in the MasterPage?
In my MasterPage I have this:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
In my aspx content page I have this:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
...
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
In my aspx.cs content page I have this:
string message = "Deleted user: " + userName;
Globals.DisplayMessage(message, 200, 100, false, this.Page);
In my static method I have this:
public static void DisplayMessage(string message, int width, int height,
bool error, Page currentPage)
{
string title;
if (error)
title = "Error";
else
title = "Alert";
RadAjaxManager.GetCurrent(currentPage).ResponseScripts.Add(
"radalert('" + message.Replace("'", "\'") +
"<br />', " + width + ", " + height + ",'" + title + "'); return false;");
}
In my MasterPage I have this:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" />
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
In my aspx content page I have this:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
...
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
In my aspx.cs content page I have this:
string message = "Deleted user: " + userName;
Globals.DisplayMessage(message, 200, 100, false, this.Page);
In my static method I have this:
public static void DisplayMessage(string message, int width, int height,
bool error, Page currentPage)
{
string title;
if (error)
title = "Error";
else
title = "Alert";
RadAjaxManager.GetCurrent(currentPage).ResponseScripts.Add(
"radalert('" + message.Replace("'", "\'") +
"<br />', " + width + ", " + height + ",'" + title + "'); return false;");
}