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

Window not opening after first time

8 Answers 222 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
rahul
Top achievements
Rank 1
rahul asked on 17 May 2011, 10:41 AM
I have a page where I am using Telerik window to open a page using ajaxRequest. It work beautifully. However next time when I hit that button, it just doesn't do anything. Below is the code snippet:
var url = "/workbench/createscenario?opportunityid=" + opportunityid + "&customerid=" + customerid
		var window = $("#wndNewScenario").data("tWindow");
window.ajaxRequest(url);
window.center();
window.open();
I even tried with full client side script as below:

	    var url = "/workbench/createscenario?opportunityid=" + opportunityid + "&customerid=" + customerid;

    var windowElement = $.telerik.window.create({
        title: "Form",
        html: '',
        contentUrl: url,
        modal: true,
        resizable: true,
        draggable: true,
        onClose: function (e) {
            alert("destroying");
            e.preventDefault();
            windowElement.destroy();

        },
        onRefresh: function (e) {
            windowElement.center();
        }

    }).data('tWindow');

    windowElement.center().open();

Any help would be much appreciated ....I really don't want to try out another popup

8 Answers, 1 is accepted

Sort by
0
bengu
Top achievements
Rank 1
answered on 19 Jul 2011, 12:20 PM
I am searching for the solution of this issue for hours, it is really boring. I also use window component in my test project. If I use constant content like:
    html: "<strong>Inserting an image...</strong>",

there is no error. But if I use ajaxRequest,  for the first time also there is no problem.
    window.ajaxRequest("/Test/Test1");

But then I cannot re-open the window. I need help, thanks.
0
Marc Simkin
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 07 Aug 2011, 05:17 PM
Are you calling $.telerik.window.create each time you open the window?  I'm asking because your close function is destroying the window.  Therefore, if you just try to call window.open() after the first time, the window doesn't actually exist.
0
Steven
Top achievements
Rank 1
answered on 11 Oct 2011, 10:40 PM
Any response on this?

It appears as if $.telerik.window.create is undefined on the second attempt to create a window.

jQuery('.actionLinks').click(function(e) {
           e.preventDefault();
           var windowElement = $.telerik.window.create({
               name: "Window",
               title: $('#'+this.id).attr('title'),
               contentUrl: $('#'+this.id).attr('data-contentUrl'),
               modal: true,
               resizable: false,
               draggable: true,
               scrollable: false,
               width: 870,
               height: 260,
               visible: false,
               onClose: function() {
                   e.preventDefault();
                   windowElement.destroy();
               }
           }).data('tWindow');
           windowElement.center().open();
       });
0
Denis
Top achievements
Rank 1
answered on 13 Oct 2011, 05:17 AM
Same problem.
tried to use:
1) ajaxRequest for loading content as shown:
function loca_edit(id) {
    var win = $("#win1").data("tWindow");
    win.ajaxRequest('@Url.Action("Edit", "Loca")' + '/' + id);
    win.center();
    win.open();
}
...
@{ Html.Telerik().Window()
        .Name("win1")
        .Title("Edit")
        .Draggable(true)
        .Modal(true)
        .Buttons(b => b.Close())
        .Width(800)
        .Height(400)
        .Visible(false)
        .Render();
}

2) $.telerik.window for creating new window instance each time - worked only first time
3) $.get ... and open window after this

After this investigating I can say in conclusion:
- window working fine if content remain static and don't change with server request (typical example http://demos.telerik.com/aspnet-mvc/razor/window )
- window working fine only first time if I made server request for content loading
0
Dimo
Telerik team
answered on 14 Oct 2011, 04:42 PM
Hello,

Here is a working example that shows how to load Window content with Ajax and open/close it multiple times. Please note that ajaxRequest works only with partial views within the same domain.

I was able to reproduce a problem with the Window not opening after the first time if the loaded content is not a partial view, but a complete web page, which is incorrect.


Master page

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
 
<!DOCTYPE html>
<html>
<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<%: Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.vista.css")) %>
    <asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
<body>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<%: Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true)) %></body>
</html>

Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc.UI;
 
namespace MVC3TestsCS.Controllers
{
    public class HomeController : Controller
    {
 
        public ActionResult Window()
        {
            return View();
        }
 
        public ActionResult WindowContent()
        {
            return PartialView();
        }
 
    }
}


View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Simple.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Window
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
<h2>Window</h2>
 
<%= Html.Telerik().Window()
    .Name("Window1")
    .Title("Window1")
    .Width(600)
    .Height(500)
    .Visible(false)
%>
 
<button type="button" onclick="openWindow1()">Open Window 1</button>
<button type="button" onclick="openWindow2()">Open Window 2</button>
 
<script type="text/javascript">
 
function openWindow1() {
    var url = "/Home/WindowContent/";
    var window = $("#Window1").data("tWindow");
    window.ajaxRequest(url);
    window.center().open();
}
 
function openWindow2() {
    var window = $.telerik.window.create({
        name: "My Window",
        title: "Window Title",
        contentUrl: "/Home/WindowContent/",
        modal: true,
        resizable: false,
        draggable: true,
        scrollable: false,
        width: 870,
        height: 260,
        visible: false,
        onClose: function() {
            window.destroy();
        }
    }).data('tWindow');
    window.center().open();
}
 
</script>
 
<% Html.Telerik().ScriptRegistrar()
    .DefaultGroup(group => group
        .Add("telerik.common.js")
        .Add("telerik.draganddrop.js")
        .Add("telerik.window.js"));
%>
 
</asp:Content>


Greetings,
Dimo
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Steven
Top achievements
Rank 1
answered on 14 Oct 2011, 07:41 PM
Thanks this helps a lot
0
David A.
Top achievements
Rank 1
answered on 02 Nov 2011, 06:23 AM
I had the same exact problem.  In my my view that was displayed in the window, I had a ScriptRegistrar() and StyleSheetRegistrar() defined as well as in the main _Layout.cshtml.  When I removed this from the view in the window, it worked.
0
Maks
Top achievements
Rank 1
answered on 07 May 2012, 12:42 PM
the same worked for me
Tags
Window
Asked by
rahul
Top achievements
Rank 1
Answers by
bengu
Top achievements
Rank 1
Marc Simkin
Top achievements
Rank 2
Iron
Veteran
Iron
Steven
Top achievements
Rank 1
Denis
Top achievements
Rank 1
Dimo
Telerik team
David A.
Top achievements
Rank 1
Maks
Top achievements
Rank 1
Share this question
or