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

Issue with RadWindow inside usercontrol

6 Answers 106 Views
Window
This is a migrated thread and some comments may be shown as answers.
Nishant
Top achievements
Rank 1
Nishant asked on 05 Jul 2013, 11:37 PM
Hi,

I have a UserControl that contains a RadWindow by the name of 'SubWindow'.

Problem 1
If I use this user control in a Page, that also contains a RadWindow called 'SubWindow', then the window.radopen('xyz.aspx, 'SubWindow') calls in the javascript of the Page start using the window of this user control, instead of the one on the page.

Problem 2
If I change the name of the RadWindow in UserControl to 'UploadWindow', then window.radopen('xyz.aspx, 'SubWindow') calls in the javascript of the Page start using a generic window instead of the one on the page.


How can I enforce use of the RadWindow on the Page by all javascript functions on the Page, and RadWindow of the UserControls by all the javascript in the UserContorl.

6 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 10 Jul 2013, 10:42 AM
Hi Nishant,

This is the expected behavior of the control and here is why:
- it seems you have a RadWindowManager on each user control. The radopen() function, however, uses the first instance on the page. Read more about opening the correct RadWindow when multiple RadWindowManagers are rendered on the page here: http://www.telerik.com/help/aspnet-ajax/radwindow-troubleshooting-wrong-window-opened.html.
- when radopen() is called and there isn't a popup with the designated name the manager that is tied to this radopen() call will open a generic RadWindow with the settings from this manager. This is explained here: http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html.
- when working with user controls I would advise that you make sure your JavaScript functions in the UCs are uniquely named, as explained here: http://www.telerik.com/support/kb/aspnet-ajax/general/using-dynamic-unique-names-for-javascript-functions.aspx to avoid them overriding each other.

What I would advise is the following:
- remove the RadWindowManagers from each user control
- use the $find().show() approach to open a popup specific for each user control
- use the approach from the KB I linked above to ensure each user control uses unique function names so that is properly encapsulates its own functionality
- you can also consider using the separate RadWindow's OpenerElementID property from the code-behind as shown here.


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
Nishant
Top achievements
Rank 1
answered on 13 Jul 2013, 07:07 PM
Hi Marin,

Thanks a lot ! Using OpenerElementID with the NavigateURL set to Response.ApplyAppPathModifier(page) worked great here. 

I just have one more challenge that remains. My UserControl contains a Panel, that I want to Ajaxify when the RadWindow closes (as the OnClientClose method of the RadWindow makes an Ajax call handled by the AjaxManager).

So, In the Page_Load method of the UserControl, I add the Panel in the AjaxSettings of the AjaxManager.

protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(manager_AjaxRequest);
    UploadWindow.NavigateUrl = Response.ApplyAppPathModifier("/Pages/UploadFile.aspx?Action=Add");
 
    //If the Parent control is already an Ajaxified Panel then there is no need to Ajaxify the FileLinksPanel
    if (!(this.Parent is Panel))
        manager.AjaxSettings.AddAjaxSetting(FileLinksPanel, FileLinksPanel);
}

It works fine for the first instance of the control, but the subsequent instances do not have the Panel Ajaxified. How do I solve this ?


Nishant
0
Marin Bratanov
Telerik team
answered on 17 Jul 2013, 10:53 AM
Hi Nishant,

I am not aware of the exact structure of the project and I cannot say what the issue might be.
What I can suggest, however, is to encapsulate this functionality in the user control as well - adding an aspUpdatePanel with a hidden button in it will let you initiate a partial postback AND have a Click handler in the user control:
<script type="text/javascript">
    function OnCLientCloseHandler<%=this.ClientID %>()
    {
        __doPostBack("<%=this.Button1.UniqueID %>", "");
    }
</script>
<asp:UpdatePanel ID="Updatepanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Button ID="Button1" Text="" Style="display:none;" OnClick="Button1_Click" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>

where the OnClientClose handler is attached to each RadWindow instnace as I advised before. This will let you avoid using the RdAjaxManager from the main page and should keep the functionality inside the user control, so it does not depend on external logic. You could also replace the UpdatePanel with RadAjaxPanel.

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
Nishant
Top achievements
Rank 1
answered on 17 Jul 2013, 07:02 PM
That worked out well. Thanks a lot !
0
Nishant
Top achievements
Rank 1
answered on 18 Jul 2013, 04:02 AM
Oh i was too early to call it a solution. The problem still remains.

The Window OnClientClose handler below works only for the first instance of the control.

function UploadWindowClose_<%= this.ClientID %>(sender, args) {
    if (args.get_argument() != "Cancel") {
        __doPostBack("<%=this.RefreshButton.UniqueID %>", "");
    }
}


For the second instance, i get an error : Microsoft JScript runtime error: 'UploadWindowClose_ctl00_MainContent_413' is undefined


0
Marin Bratanov
Telerik team
answered on 19 Jul 2013, 11:03 AM
Hello Nishant,

This means that the JavaScript functions are not properly declared in the markup, or that the user controls are loaded with a partial postback, in which case the inline scripts will not be parsed by the framework and the browser. In this case they would need to be registered, e.g. with the RegisterClientScriptBlock() method of the ScriptManager static class. You can also try providing IDs to your user controls to make them more static and avoid random changes.


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.
Tags
Window
Asked by
Nishant
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Nishant
Top achievements
Rank 1
Share this question
or