This question is locked. New answers and comments are not allowed.
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
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>