This is a migrated thread and some comments may be shown as answers.

Dynamically Created RadWindow not opening

11 Answers 249 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jamie
Top achievements
Rank 1
Jamie asked on 14 May 2012, 07:12 PM
I have a CMS edit page which used RadMultiPage to display dynamically created controls, depending what fields are needed.

<telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop" AutoPostBack="false"
CausesValidation="false" SelectedIndex="0" MultiPageID="RadMultiPage1">
 
<Tabs />
 
</telerik:RadTabStrip>
<telerik:RadMultiPage runat="server" ID="RadMultiPage1" />

The page basically executes like this:

  1. I dynamically create a new RadPageView
  2. I create new fields depending on their type and give it a unique ID depending on the Field ID
  3. I add the field controls into a PlaceHolder
  4. I add the PlaceHolder into the new RadPageView

This works fine, but I am adding functionality where a modal RadWindow opens up when a button is clicked.

label = new Label();
label.ID = rdr["TITLE"].ToString().Replace(" ", "") + rdr["FIELDID"].ToString() + "Label";
label.Text = rdr["TITLE"].ToString();
 
window = new Telerik.Web.UI.RadWindow();
window.Height = 550;
window.Width = 560;
window.VisibleStatusbar = false;
window.ShowContentDuringLoad = false;
window.ID = rdr["TITLE"].ToString().Replace(" ", "") + rdr["FIELDID"].ToString() + "MediaWindow";
window.Modal = true;
window.Behaviors = Telerik.Web.UI.WindowBehaviors.Close | Telerik.Web.UI.WindowBehaviors.Move;
window.NavigateUrl = "~/Explorer.aspx";
 
button = new Button();
button.ID = rdr["TITLE"].ToString().Replace(" ", "") + rdr["FIELDID"].ToString() + "MediaWindowButton";
button.OnClientClick = String.Format("OpenFileExplorerDialog(\"{0}\"); return false;", window.ClientID);
button.Text = "Media Library";
 
div = new HtmlGenericControl("div");
div.EnableViewState = true;

div.Controls.AddAt(0, window);
div.Controls.AddAt(0, button);
div.Controls.AddAt(0, label);
 
InputFieldsPlaceHolder.Controls.AddAt(InputFieldsPlaceHolder.Controls.Count, div);

I've been using the http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/client-sideapi/fileselectordialog/defaultcs.aspx demo and can get the desired results outside a RadMultiPage control so I assume this is the problem.  When I debug the javascript (below) I get that the wnd variable is null.  I've placed it EVERYWHERE on the page.

<script type="text/javascript">
    function OpenFileExplorerDialog(x) {
        var wnd = $find(x);
        wnd.show();
    }
</script>

The RadWindow div is created and present in the source as is the add_init function near the end of the form tag.

Any ideas?

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 May 2012, 06:29 AM
Hello Jamie,

Try adding the dynamically created window to the RadWindowManger.
aspx:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
C#:
RadWindowManager1.Controls.Add(NewWindow);
Button2.OnClientClick = String.Format("OpenFileExplorerDialog(\"{0}\"); return false;", NewWindow.ClientID);

Thanks,
Princy.
0
Jamie
Top achievements
Rank 1
answered on 15 May 2012, 09:38 AM
Hi Princy

Thank you for your speedy response.  However, the problem still persists.
0
Jamie
Top achievements
Rank 1
answered on 15 May 2012, 09:57 AM
I might have this...  The ACTUAL client ID of the RadWindow is "ctl00_PrimaryContentPlaceHolder_WINDOWID", but the string passed to the function is "WINDOWID"...

I'll keep everyone informed... :)
0
Jamie
Top achievements
Rank 1
answered on 15 May 2012, 10:18 AM
Got it!

It seems to be a problem with automatically generated ClientIDs.  When the link between the Button and RadWindow is made using the onclick, as far as the system is aware the clientId is "WINDOWID", but when it is put into a controlcollection it takes on its parent's ID too "ParentId_WINDOWID" - but the button isn't aware of this and still calls it "WINDOWID".

by adding the following delcaration:
window.ClientIDMode = System.Web.UI.ClientIDMode.Static;

you're telling the system to keep whatever ID I give it as it's client ID.  As I'm creating unique IDs anyway this will be fine.
0
Marin Bratanov
Telerik team
answered on 16 May 2012, 11:55 AM
Hello Jamie,

While I am glad to see you have resolved the situation I'd like to add a few comments.

1) We do note recommend setting the ClientIDMode to static, because our controls are complex and often are containers themselves, so overriding this property can break further functionality down the hierarchy

2) the CilentID is evaluated by the framework after the control is added to the control tree of the page, so if you add your newly created RadWindow to the page before you add the handler for the button you should not have problems with the original approach as you would have the correct ClientID

Nevertheless, if you find your current code works fine and does not cause problems you can keep it as it is now.


Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rohan
Top achievements
Rank 1
answered on 09 Nov 2012, 01:56 PM
Hi all ,
I am facing the same issues ... i tried solution that was provided but does not work for me ..... here is my code
 RadWindow radwindow = new RadWindow();
radwindow.ID = "SearchUserWindow";
                RadAjaxPanel panel = new RadAjaxPanel();
                panel.ID = "rp1";
                radwindow.ContentContainer.Controls.Add(panel);
                panel.Controls.Add(plhGrd);
                ImageButton1.OnClientClick = String.Format("ShowUserforSendFileWindow(\"{0}\"); ", radwindow.ClientID);

This is Javascript function
  function ShowUserforSendFileWindow(x) {
        
          var oWindowCust = $find(x);
          oWindowCust.show();

      }
            
i also try with radwindowmanager but works ... please provide any solution or document to refer ... Thanks ....
0
Princy
Top achievements
Rank 2
answered on 12 Nov 2012, 07:29 AM
Hi Rohan,

I have made some changes in your code and it worked as expected. Please make sure that you are adding the RadWindow control to the form.

C#:
RadWindow radwindow = new RadWindow();
radwindow.ID = "SearchUserWindow";
RadAjaxPanel panel = new RadAjaxPanel();
panel.ID = "rp1";
radwindow.ContentContainer.Controls.Add(panel);
panel.Controls.Add(plhGrd);
form1.Controls.Add(radwindow);
ImageButton1.OnClientClick = String.Format("ShowUserforSendFileWindow(\"{0}\"); return false;", radwindow.ClientID);

JS:
<script type="text/javascript">
    function ShowUserforSendFileWindow(x) {
        var oWindowCust = $find(x);
        oWindowCust.show();
    }
</script>

Hope this helps.

Regards,
Princy.
0
Rohan
Top achievements
Rank 1
answered on 12 Nov 2012, 12:55 PM
Hi Princy,

Thanks Princy ..... it solve my problem ....
Once again thanks for help...
0
Lynn Sweet
Top achievements
Rank 1
answered on 12 Jul 2013, 10:31 PM
Hello,

I am using radwindowmanager in a complex page: i will try to be as clear as I can. Here's the scenario:

- I have an aspx page that holds RadWindowManager
- a user control (header) that contain scriptManager and
- another user control (this user control is loaded dynamically from a class using 
page.LoadControl("control.ascx");
The above mentioned user control creates a dynamic radwindows and adds those to RadWindowManager like:
RadWindowManager RadWindowManager1 = (RadWindowManager)
this.Page.FindControl("RadWindowManager1");


I am adding radWindows in a loop like:
for(int i=0; i<1000; i++)
{
RadWindow win = new RadWindow();
win.ID = "radwin_" + i;
win.OpenerElementID = "radwinOpener_" + i;
win.Attributes["MyAttribute"] = "SomeAttribute";
win.VisibleOnPageLoad = false;
win.AutoSize = true;
win.Modal = true;
win.ReloadOnShow = true;
win.Animation = WindowAnimation.FlyIn;
win.NavigateUrl = this.hdbookedurl.Value;
//if (RadWindowManager1 != null)
{
    RadWindowManager1.Windows.Add(win);
}
this.bookedInfoDiv.Attributes.Add("onclick", "openWinNavigateUrl('" + win.ClientID + "',''); return false;");
}
This works fine!
Now after the page is loaded I have a timer and an updatePanel in the aspx page that loads the rest of the page data but using the
same above scenario like: The timer only run once.
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="5000">
</asp:Timer>
<asp:UpdatePanel ID="updatePanel" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
    <ContentTemplate>
<asp:Table runat="server" ID="table_test" Width="" CellPadding="0" CellSpacing="0"></asp:Table>
<telerik:RadButton ID="btnMore" Visible="false" runat="server" Text="Loading More..." OnClick="btnMore_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
When I debug the code it is adding the radWindows to radWindowsManager just fine but on the viewSource I am not seeing the radwindows.
javascript on aspx page for radwindow throws error as well on oWnd.setUrl(url)
The error is  Unable to get property 'setUrl' of undefined or null reference.
function openWinNavigateUrl(winClientId, url) {
    alert(winClientId);
    var oWnd = $find(winClientId);
    if (url != '') {
        oWnd.setUrl(url);
    }
    oWnd.show();
What am I missing here that RadWindow won't open? Any help would be greatly appreciated! Thank you
0
Marin Bratanov
Telerik team
answered on 17 Jul 2013, 10:01 AM
Hello Lynn,

I would advise opening your RadWindows with JavaScript alone instead of creating instances in the code-behind. The following article explains how to do this: http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html. You can consider using page methods or webservices to get the URL if you can get it only from the code-behind. This blog post may help you choose.
Once you open a new popup instance you can use its client-side API ot set the desired properties (modality, url, behaviors, etc.) as shown in the above article.

My best guess on the exact issue is that the RadWindowManager is not included in the partial update from the server, so the new RadWindow instances are not transferred to the browser. You would need to either use the JS approach I advise, or include the RadWindowManager in the partial postback from the timer.
Another possible reason for the error is that the scripts may be executing too early and this is treated in this sticky thread and this help article (note the Sys.Application.Load event).


Regards,
Marin Bratanov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Robert
Top achievements
Rank 2
answered on 23 Jan 2014, 03:29 PM
The clientID of the dynamically generated opener control was my problem as well.  The easy solution is in the pre render event of the container page, set the opener control id at that point because at that stage the clientID has been set properly:

// Use public properties to expose the rad window and the opener button ID
	dynamicallyCreatedUserControl.PopupWindow.OpenerElementID = 
dynamicallyCreatedUserControl.PopupOpenerControlID;
Tags
Window
Asked by
Jamie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jamie
Top achievements
Rank 1
Marin Bratanov
Telerik team
Rohan
Top achievements
Rank 1
Lynn Sweet
Top achievements
Rank 1
Robert
Top achievements
Rank 2
Share this question
or