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

[Solved] Window losing reference after closed

3 Answers 154 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.
Jon
Top achievements
Rank 1
Jon asked on 20 Mar 2011, 01:26 AM
Hi,

I have a window that I am using for multiple requests on a page.  A 'create' and 'edit' button both use the same window and are replacing the ajax request in between calls.  It works fine the first time, but the second call, the jquery search for the window.data returns null and I get an exception.

I have tried all sorts of different approaches and none seem to work.  Below is my view code...

Any ideas?

thanks so much,

-Jon

@model FieldLevelAssessments.ViewModels.BaseViewModel
@{
    ViewBag.Title = "Index";
}
<h2>
    Risk Assessments</h2>
<div id="riskAssessmentBody">
    <table width="100%" border="0">
        <tr>
            <td>
                @(Html.Telerik().Menu()
                        .Name("LinesOfBusinessMenu")
                        .Orientation(MenuOrientation.Horizontal)
                        .BindTo(Model.LinesOfBusiness, mappings =>
                        {
                            mappings.For<string>(binding => binding
                                    .ItemDataBound((item, lob) =>
                                    {
                                        item.Text = lob;
                                        item.ControllerName = "riskassessments";
                                        item.ActionName = "index";
                                        item.RouteValues = new RouteValueDictionary(new { lineOfBusinessName = lob });
                                    }));

                        }))
            </td>
            <td>
                <table>
                    <tr>
                        <td>
                            <div id="riskassessmentscontainer">
                                <div id="sites">
                                    @Html.DropDownListFor(x => x.Sites, new SelectList(Model.Sites, "Id""Name"))
                                </div>
                                <div id="riskAssessments">
                                    @(Html.Telerik().Grid<Teck.FieldLevelAssessments.Core.Models.RiskAssessment>()
                                        .Name("Grid")
                                        .Columns(columns =>
                                        {                                            
                                            columns.Bound(o => o.AssessorName).Width(100);
                                            columns.Bound(o => o.Location).Width(200);
                                            columns.Bound(o => o.AssessmentDate).Format("{0:MM/dd/yyyy}").Width(120);
                                            columns.Bound(o => o.Id).Sortable(false).HeaderHtmlAttributes(new {@style="display:none;"}).HtmlAttributes(new {@style="display:none;"});
                                        })
                                        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding""RiskAssessments"new { siteId = Model.SelectedSite.Id.ToString() }))
                                        .Selectable()
                                        .Pageable()
                                        .Sortable()
                                        .Scrollable()
                                        .Groupable()
                                        .Filterable()
                                        .ClientEvents(events => events
                                            .OnRowSelect("onRowSelect")
                                            )
                                     )
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <button id="editRiskAssessment" disabled="disabled" class="t-button">
                                Edit</button>
                            <button id="newButton" class="t-button">
                                New</button>
                            <button id="deleteButton" disabled="disabled" class="t-button">
                                Delete</button>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
@(Html.Telerik().Window()
    .Name("Editor")
    .Buttons(buttons => buttons.Refresh().Maximize().Close())
    .Width(450)     
    .Height(450)
    .Draggable(true)
    .Visible(false)
)
@(Html.Telerik().ScriptRegistrar().Scripts(scripts =>
            scripts.AddGroup("CommonScript", group =>
                    group.Add("~/Scripts/2010.3.1318/telerik.window.min.js")))
         )
         
   <script type="text/javascript">



       function loadRiskAssessmentNewWindow() {

           var window = $("#Editor").data("tWindow");

           window.ajaxRequest("/riskassessments/create/"); 
           window.Title = "Create";
           window.refresh();
           window.center();           
           window.open();           
       }

       function loadRiskAssessmentEditWindow(id) {
       
           var window = $("#Editor").data("tWindow");
          
           window.ajaxRequest("/riskassessments/edit/" + id);
           window.Title = "Edit";
           window.refresh();
           window.center();
           window.open();
       }

       
       var currentRiskAssessmentId;

       $(document).ready(function () {

           $("#editRiskAssessment").click(function () {

               loadRiskAssessmentEditWindow(currentRiskAssessmentId)
           });

           $("#newButton").click(function () {

               loadRiskAssessmentNewWindow();
           });

           $("#Sites").change(function () {
               var riskAssessmentGrid = $('#Grid').data('tGrid');
               newSiteId = $(this).val();

               // rebind the related grid
               riskAssessmentGrid.rebind({
                   siteId: newSiteId
               });
           });
       });

       function onRowSelect(e) {
           var row = e.row;
           currentRiskAssessmentId = row.cells[3].innerHTML;
           $("#editRiskAssessment").removeAttr("disabled");
           $("#deleteButton").removeAttr("disabled");           
       }
   </script>

3 Answers, 1 is accepted

Sort by
0
Jon
Top achievements
Rank 1
answered on 20 Mar 2011, 01:40 AM
I also notice that when I use the pure client API side, with this example:

function ShowLookupWindow(param) {
           lookupWindow = $.telerik.window.create({
               name: "LookupWindow",
               title: "Lookup",
               contentUrl: param,
               modal: true,
               resizable: true,
               draggable: true,
               width: 700,
               height: 350,
               minHeight: 250,
               minWidth: 250,
               maxHeight: 500,
               maxWidth: 500,
               onClose: function (e) {
                   e.preventDefault();
                   lookupWindow.data('tWindow').destroy();
               }
           });
           lookupWindow.data('tWindow').center().open();
       }

It results in the same.  If I remove the content URL parameter that i am passing in, the window performs normally (I dont lose reference to the window object) but I don't have any data in the form of course.

0
Jon
Top achievements
Rank 1
answered on 25 Mar 2011, 01:49 AM
No response? :(  That's a bummer...
0
Stewart
Top achievements
Rank 1
answered on 11 Jul 2011, 09:13 PM
Tags
Window
Asked by
Jon
Top achievements
Rank 1
Answers by
Jon
Top achievements
Rank 1
Stewart
Top achievements
Rank 1
Share this question
or