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

Cannot close RadWindow using Ajaxified button

5 Answers 176 Views
Window
This is a migrated thread and some comments may be shown as answers.
Bex
Top achievements
Rank 1
Bex asked on 11 May 2012, 04:03 PM
Hi
I have been through these forums and found lots of similar examples but none that quite fix my problem.
I have a rad window with a content template that pops up on click of a button.
The user must complete certain things that are checked on the server within the rad window unless an error message is shown, otherwise the details added are saved and the window needs to close.

My problem is my rad window doesn't close!

This is my radwindow 
<telerik:RadWindowManager ID="Radwindowmanager1" runat="server">
    <Windows>
        <telerik:RadWindow runat="server" ID="winDetail" Width="400px" Height="400px"
            ReloadOnShow="true" ShowContentDuringLoad="false" Modal="True" Behaviors="None"
            VisibleTitlebar="true" VisibleStatusbar="false">
            <ContentTemplate>
             
                    <h3>
                        Injury Details
                    </h3>
                    <asp:Label runat="server" ID="lblError"></asp:Label>
                    <div class="modalForm">
                        <ol>
                            <li>
                                <label class="noFloatLabel">
                                    Injury
                                </label>
                                <telerik:RadComboBox ID="ddlName" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlInjuryName_OnSelectedIndexChanged" />
                                <telerik:RadTextBox runat="server" ID="txtNewName">
                                </telerik:RadTextBox>
                            </li>
                            <li>
                                <label class="noFloatLabel">
                                    Specific Detail
                                </label>
                                <telerik:RadComboBox ID="ddSpecific" runat="server" />
                                <telerik:RadTextBox runat="server" ID="txtNewSpecific">
                                </telerik:RadTextBox>
                            </li>
                        </ol>
                    </div>
                    <br />
                    <asp:Button runat="server" ID="btnAddDetail" Text="Add" OnClick="btnAddDetail_Click" />
            <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClick="btnCancel_Click" />
         <asp:HiddenField runat="server" ID="hdnId" />
            </ContentTemplate>
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>

I am using an ajax manager to try and control the autopopulation of my dropdowns and btnAddDetail with the error message.
<telerik:RadAjaxManager runat="server" ID="aj1">
    <AjaxSettings>
        
        <telerik:AjaxSetting AjaxControlID="ddlName">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="ddlSpecific" />
            </UpdatedControls>
        </telerik:AjaxSetting>
         <telerik:AjaxSetting AjaxControlID="btnAddDetail">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="lblError" />
                 
            </UpdatedControls>
        </telerik:AjaxSetting>
         
    </AjaxSettings>
</telerik:RadAjaxManager>

When I click the btnAddDetail 

I run this function
protected void btnAddDetail_Click(object sender, EventArgs e)
        {
 
            if ((ddlName.SelectedValue != string.Empty || txtNewName.Text != string.Empty)
                && (ddlSpecific.SelectedValue != string.Empty || txtNewSpecific.Text != string.Empty))
            {
//do processing if processing fails show error if not close window
 
string script = "function f(){Close(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";         
    ScriptManager.RegisterStartupScript(
this, this.GetType(), "close", script, true);

            }
            else
            {
                lblError.Text = "You must select a name and description";
            }
        }


This is my javascript to close the window:
function GetRadWindow() {
          var oWindow = null;
          if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
          else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)
          return oWindow;
      }
 
      function Close() {
          GetRadWindow().close();
      }


Can anyone help with my my window won't close? I know its something to do with how I've used the ajax but I can't work out what!

Bex

5 Answers, 1 is accepted

Sort by
0
Bex
Top achievements
Rank 1
answered on 14 May 2012, 09:22 AM
Anyone?
0
Marin Bratanov
Telerik team
answered on 15 May 2012, 03:46 PM
Hello Bex,

You are using the RadWindow with its ContentTemplate, so the controls inside (including the button you wish to use for closing) reside in the same page as the RadWindow. The GetRadWindow() function you are using is designed to get a reference to the RadWindow from within a page that is loaded inside (via its NavigateUrl property).

What you need to call is $find(your_RW_ClientID).close() instead. This is shown in action in the following online demo that explains the difference between the two modes: http://demos.telerik.com/aspnet-ajax/window/examples/contenttemplatevsnavigateurl/defaultcs.aspx.


Kind 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
Bex
Top achievements
Rank 1
answered on 15 May 2012, 04:00 PM
Hi Marin

Thanks for your reply.
I just tried this and it does not work.
That example you gave me a link to was the first thing I tried.
I think it's something to do with my Ajax setting:

<telerik:AjaxSetting AjaxControlID="btnAddDetail">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="lblError" />
                 
            </UpdatedControls>
        </telerik:AjaxSetting>

If I remove it even the GetRadWindow().close function works, but when I put the ajax back it does not.
I may be using the ajax wrongly but I was unsure which forum to put it in as it was the rad window I was having the problem with.

Bex
0
Marin Bratanov
Telerik team
answered on 17 May 2012, 03:33 PM
Hi Bex,

I build a sample for you that I based on the code you pasted initially and things are working properly with me. You can find it attached here and there is also a screen capture in it that shows the behavior. This leads me to believe that some condition in your server code is not met and the Close() function is not called at all, so I suggest you debug your code and see if this is the case. You can also compare your actual page with my sample and try to find the major difference that is causing the problem. For example, if this is inside a user control you may need to reference the page in order for the script registration to work, e.g.:
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "close", script, true);



Greetings,
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
Bex
Top achievements
Rank 1
answered on 18 May 2012, 08:51 AM
Marin

Thank you for the example.

I have tested your example and updated it slightly as I am using a user control and your example works!
(This is an update as prev it didn't but I had the javascript in the wrong place!)
Mine is still not working though  as I get a javascript error so I may have a few more questions soon!


Bex
Tags
Window
Asked by
Bex
Top achievements
Rank 1
Answers by
Bex
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or