0

我有一个 Telerik 弹出窗口。它可以正常打开;但是,我在关闭窗口时遇到问题。如果我向 javascript、alert("#Window") 或 alert($(this).closest('#Window')) 添加警报,它将显示 [object Object]。但是,alter("#Window").data("tWindow") 或 alert($(this).closest('#Window').data('tWindow')) 将显示 null。我已经从父页面或子页面中删除了 jquery 和 javascript 引用,它没有任何区别。任何形式的帮助将不胜感激。请参阅下面的示例代码

这是弹出窗口:

@{Html.Telerik().Window()
     .Name("Window")
     .Title("Student Window")
     .LoadContentFrom(Url.Action("AddReason", "Reason", new { id = reasonID }, Request.Url.Scheme))
     .ClientEvents(events => events
         .OnClose("ClosingWindow")
         )
     .Draggable(false)
     .Scrollable(false)
     .Width(800)
     .Height(600)
     .Modal(true)
     .Visible(false)
     //.Effects(fx => fx
     //    .Zoom()
     //    .Opacity())
     .Render();
 }

这是JavaScript:

  <script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript">

</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/spin.min.js")" type="text/javascript"></script>


function DoOpen(id) {
        var url = '@Url.Action("AddReason","Reason")';
        $.post(url, { id: id }, function (data) {
            var window = $('#Window').data('tWindow').center();
            window.content(data);
            window.open();
        });
   }
 //This javascript is in the main page
//I did an alert. alert($('#Window')) and 
alert($('#Window').data('tWindow')) they both return null

  function ClosingWindow() {
      $('#Window').prop("checked", "checked");
      $('#Window').data('tWindow').close();
       window.location.href = window.location.href;
   }

Here is the partial view :

    @model Student.Models.Reason
@using Student.Example

@{
    ViewBag.Title = "Add Reason";
    Layout = "~/Views/Shared/_PartialReason.cshtml";
}

<script type="text/javascript">
    function CloseWindow() {
//        alert($("#Window").closest('.t-window').data('#tWindow'));
//        $("#Window").data("tWindow").close();
        $('#Window').prop("checked", "checked");
         window.location.href = window.location.href;
    }

</script>

@using (Html.BeginForm("AddReason", "Reason", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="editor-field">
            @(Html.Telerik().Editor()
            .Name("EncountersArchive")
            .HtmlAttributes(new { style = "height:310px;", id = "AddAReason" })
            .Encode(true)
            .Tools(
            tools => tools
                       .Clear()
                        .Bold().Italic().Underline().Strikethrough().Subscript().Superscript().Separator()
                        .FontName().FontSize()
                        .FontColor().BackColor().Separator()
                        .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().Separator()
                        .InsertUnorderedList().InsertOrderedList().Separator()
                        .Indent().Outdent().Separator()
            ))
        </div>
        <p style="text-align:center">

            <input type="submit" value="Reason" id="AddReasonID" onclick="CloseWindow()"/>
        </p>
    </fieldset>
}
4

1 回答 1

0

弹出窗口上的 OnClose 事件导致了该问题。仅当用户希望在窗口关闭后执行其他操作时才应使用 onclose 事件。如果目的只是关闭窗口,Telerik 控件会自动处理它。就我而言,我只是删除了 onclose 事件,它就像一个魅力。

于 2013-04-05T01:57:06.723 回答