title: Kendo UI - Why can't I open and close properly a window?
body: <p>I've tried different methods to open my window, but so far everything fails.</p>
  
  <p>My first try was to open the window when a button was clicked with a code like this based on <a href="http://demos.kendoui.com/web/window/index.html" rel="noreferrer">this</a> example:</p>
  
  <pre><code>$('#btnUsuarios').click(function (e) {
      onUsuariosLoad();
      var window = $('#usuariosDiv');
      if (!window.data('kendoWindow')) {
          window.kendoWindow({
              draggable: true,
              height: "300px",
              modal: true,
              resizable: false,
              title: "Modal Window",
              width: "65%",
              close: hideUsuarios
          });
      } else {
          window.data('kendoWindow').open();
      }
      hideHomeScreen();
      showUsuarios();
  
  });
  </code></pre>
  
  <p>onUsuariosLoad is a function that loads the content for the window from a remote html, the function makes sure to only load once the content, if it had been loaded already then it doesn't load it again, I've tested the function before trying to implement the window Kendo UI widget to make sure it works properly. </p>
  
  <p>hideHomeScreen is a function that hides some element from the div that open the window.</p>
  
  <p>showUsuarios is a function that shows the content for the window. </p>
  
  <p>It was supposed to check if the data for a kendoWindow had been created then to open the window, else it should create it. The first time I click the button it works, but when I close the window and click again the button, the window isn't show at all (I'm talking about the window widget UI, not the contents of the usuariosDiv, I checked Firebug and the contents for usuariosDiv are still there, but the window widget UI isn't shown).</p>
  
  <p>The second try I did was like this:</p>
  
  <pre><code>$('#btnUsuarios').click(function (e) {
      onUsuariosLoad();
     $('#usuariosDiv').kendoWindow({
          draggable: true,
          height: "300px",
          modal: true,
          resizable: false,
          title: "Modal Window",
          width: "65%",
          close : hideUsuarios
      });
      hideHomeScreen();
      showUsuarios();
  });
  </code></pre>
  
  <p>This is similar to the first attemp but it happens the same thing: it works fine the first time, but when I close the window it fails to reopen the window when I click again the button.</p>
  
  <p>My third try was based on the example <em>Initialize Window, center, and configure button click action</em> from <a href="http://docs.kendoui.com/documentation/getting-started/web/window/overview#initialize-window-center-and-configure-button-click-action" rel="noreferrer">this</a> page:</p>
  
  <pre><code>var win = $("#usuariosDiv").kendoWindow({
      draggable: true,
      height: "300px",
      modal: true,
      resizable: false,
      visible: false,
      title: "Modal Window",
      width: "65%",
      close: hideUsuarios
  }).data("kendoWindow");
  $('#btnUsuarios').click(function (e) {
      onUsuariosLoad();
     var win = $("#usuariosDiv").data("kendoWindow");
      win.open();
      hideHomeScreen();
      showUsuarios();
  });
  </code></pre>
  
  <p>This doesn't show the window properly, instead of showing a window with the specified dimensions, it only shows a tiny dot modal window.</p>
  
  <p>That's for the opening part, my problem with closing the window comes when I try to do it by an event triggered by a control on the window. I'm not talking about the close button on the upper right corner, I'm refering to any button I have displayed on the window.</p>
  
  <p>For example, I tried this to close the window:</p>
  
  <pre><code>$('#btnBack').click(function (e) {
      hideUsuarios();
      var window = $('#usuariosDiv');
      window.data('kendoWindow').close();
  });
  </code></pre>
  
  <p>But I get the following error: <code>Uncaught TypeError: Cannot call method 'close' of undefined</code>. If you're asking why I don't simply rely on the default close button on the window, it's because there're procedures, that when finished, need to close the window.</p>
  
  <p>This is my View:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
      &lt;link href="&lt;%: Url.Content("~/Content/kendo/2012.3.1114/kendo.common.min.css")%&gt;" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="&lt;%: Url.Content("~/Content/kendo/2012.3.1114/kendo.metro.min.css")%&gt;" rel="stylesheet" type="text/css" /&gt;
      &lt;script src="http://code.jquery.com/jquery-1.7.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="&lt;%: Url.Content("~/Scripts/kendo/2012.3.1114/kendo.web.min.js")%&gt;"&gt;&lt;/script&gt;
      &lt;script src="&lt;%: Url.Content("~/Scripts/jquery.signalR-1.0.0-rc1.min.js")%&gt;" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3" type ="text/javascript" &gt;&lt;/script&gt;
      &lt;script src="&lt;%: Url.Content("~/Scripts/index/templates.js")%&gt;" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="&lt;%: Url.Content("~/Scripts/index/main.js")%&gt;" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;style type="text/css"&gt;
          #verticalMenu {
              top: 39px;
              left: 0px;
          }
      &lt;/style&gt;
  
  &lt;/head&gt;
  &lt;body onload="onPageLoad()"&gt;
      &lt;div id="canvasDiv" style="position: absolute; top: 0px; left: 0; width: 100%; height: 100%; background-color: transparent;"&gt;
          &lt;div id="alertDiv" style="position: absolute; top: -250px; background-color: #F00; z-index: 50; opacity:1; border-top: 1px solid #FFF; border-right: 1px solid #F5F5F5; border-bottom: 1px solid #D5D5D5; border-left: 1px solid #F5F5F5"&gt;
              &lt;div id="msgDiv" style="position:absolute;left:10px; right:10px; bottom: 10px; text-align: center;width: 50%; margin: 0px auto;"&gt;Alerta Sismo Detectado&lt;/div&gt;
              &lt;div id="btnCloseAlert"  style="position: absolute; top: 0px; right: 0"&gt;&lt;span class="k-icon k-i-close"&gt;&lt;/span&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div id="homeScreenDiv" style="position: absolute; top: 0px; left: 0; width: 100%; height: 100%; background-color: white; z-index: 10; opacity:1"&gt;
  
          &lt;/div&gt;
          &lt;div id="usuariosDiv" style="position: absolute; left: 0; width: 100%; height: 100%; background-color: white; z-index: 2; opacity:0"&gt;
  
          &lt;/div&gt;
          &lt;div id="sismosDiv" style="position: absolute; left: 0; width: 100%; height: 100%; background-color: white; z-index: 2; opacity:0"&gt;
              &lt;div id="leftBar" style="border: thin solid #666666; position: absolute; top: 0px; left: 0; width: 190px; height: 100%; background-color: white; z-index:20"&gt;
                  &lt;div onclick="hideSismos()" style="position:absolute;height: 39px; width: 25%; left:0; top:0"&gt;&lt;div style="position:absolute; top: 10px; bottom:10px;left:10px;right:10px"&gt;&lt;span class="k-icon k-i-arrow-w"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
                  &lt;div style="position:absolute;height: 39px; width: 75%; right:0; top:10px; bottom:10px; text-align:center"&gt;Sismos&lt;/div&gt;
                  &lt;ul id="verticalMenu" style="position: absolute; width: 99%; height: auto; display: block;" &gt;
                      &lt;li id="Regiones" style="height: 75px; text-align: center;"&gt;Regiones&lt;/li&gt;
                      &lt;li id="Clusters" style="height: 75px; text-align: center;"&gt;Clusters&lt;/li&gt;
                      &lt;li id="Dispositivos" style="height: 75px; top: auto; text-align: center;"&gt;Dispositivos&lt;/li&gt;
                      &lt;li id="Eventos" style="height: 75px; text-align: center;"&gt;Eventos&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
              &lt;div id="selectionBar" style="border: thin solid #666666; position: absolute; top: 0px; left: 0; width: 180px; height: 100%; background-color: white; left: 10px; overflow:auto; z-index:9"&gt;
                  &lt;div class="k-toolbar k-grid-toolbar" style="height: 34px;"&gt;
                      &lt;button id="btnAgregarEntry" class="k-button k-button-icontext k-add-button" onclick="swapToNewData(this)"&gt;&lt;span class="k-icon k-add"&gt;&lt;/span&gt;Agregar&lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div id="listView" style="background-color: transparent; position: absolute; top: 40px; left: 0px; right: 0px; width:auto; height:auto" &gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div id="dataBar" style="border: thin solid #666666; position: absolute; top: 0px; left: 0; width: 330px; height: 100%; background-color: white; left: 10px; overflow:auto; z-index:8"&gt;
                  &lt;div id="dataView" style="background-color: transparent; position: absolute; top: 40px; bottom:0px; left: 0px; right: 0px; width:auto; height:auto" &gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div id='myMap' style="border: thin solid black; background-color: white; position: absolute; display: block; min-height: 100%; top: 0px; left: 189px; width: 88%; z-index: 20"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Can anyone help me to understand what am I doing wrong?</p>