Reputation: 1150
The following is the code I am using to display popup window of Telerik(Radwindow) in aspx page. It successfully displays the window with the below current code.
How can I display popup window from ASP.NET Usercontrol?
RadWindowManager windowManager = new RadWindowManager();
RadWindow window1 = new RadWindow();
window1.NavigateUrl = "Window1.aspx";
window1.ID = "RadWindow1";
window1.VisibleOnPageLoad = true; // Set this property to True for showing window from code
windowManager.Windows.Add(window1);
this.form1.Controls.Add(window1);
Upvotes: 0
Views: 5006
Reputation: 5603
You can, of course, but there are two issues with this approach:
the user control will have to know about the window manager and window on the master page, traverse the controls hierarchy and find them
if you add the entire snippet to the user control you will end up with several window manager instance and this can play a few tricks on you (see here).
So, think about the following ideas:
add a RadWindow instance to the user control (not a RadWindowManager) and use that alone. Read this article to register a script from the server in order to open it and this article on making the JS functions you may need unique per user control.
open the RadWindow purely from the client-side as shown here. You can register a JS function from the server that will pass the parameters you need (URL, modality, whatever)
Here is a sample implementation of one of the ideas (that I would go with) based on your comment:
Master page
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
<script>
function openDialog(url, modal, width, height) {
if (radopen) { //if not, there is no RadWindowManager on the page, add an else{} block to use window.open() or other logic
var wnd = radopen(url, null);
wnd.set_destroyOnClose(true);
//add checks here in case parameters have not been passed
wnd.setSize(width, height);
wnd.center();
wnd.set_modal(modal);
}
}
</script>
User control markup
<asp:Button ID="Button1" Text="open RW" OnClick="Button1_Click" runat="server" />
Use control code-behind
protected void Button1_Click(object sender, EventArgs e)
{
bool flag = true;
if(flag)
{
string script = string.Format("function f(){{openDialog('{0}', {1}, {2}, {3});Sys.Application.remove_load(f);}}Sys.Application.add_load(f);",
"the-page.aspx",
"true",
600,
400);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someKey", script, true);
}
}
Upvotes: 2