jquery - 0x800a139e - JavaScript runtime error: cannot call methods on dialog prior to initialization; attempted to call method 'close' -
i have cancel button not working on jquery modal dialog , appreciate help. exception i'm getting when click on cancel button of modal:
0x800a139e - javascript runtime error: cannot call methods on dialog prior initialization; attempted call method 'close'
this partial view i'm displaying on modal:
@model models.office @{ layout = null; } @scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryui") @styles.render("~/content/bootstrap") @scripts.render("~/bundles/bootstrap") @styles.render("~/content/css") @styles.render("~/content/themes/base/css") @scripts.render("~/bundles/modernizr") <script src="~/scripts/jquery.validate.min.js"></script> <script src="~/scripts/jquery.validate.unobtrusive.min.js"></script> <script src="~/scripts/jquery.unobtrusive-ajax.min.js"></script> <script type="text/javascript"> function closemodal() { $(this).dialog("close"); } </script> @*@using (ajax.beginform("editoffice", "admin", new ajaxoptions { httpmethod = "post", updatetargetid = "edit-dialog" }))*@ @using (html.beginform("createeditoffice", "admin", "post")) { <fieldset> <legend>office</legend> @if (viewbag.isupdate == true) { @html.hiddenfor(model => model.officeid) } <div class="display-label"> @html.displaynamefor(model => model.officename) </div> <div class="input-medium"> @html.editorfor(model => model.officename) @html.validationmessagefor(model => model.officename) </div> <div class="display-label"> @html.displaynamefor(model => model.supportno) </div> <div class="input-medium"> @html.editorfor(model => model.supportno) @html.validationmessagefor(model => model.supportno) </div> <div class="display-label"> @html.displaynamefor(model => model.supportemail) </div> <div class="input-medium"> @html.editorfor(model => model.supportemail) @html.validationmessagefor(model => model.supportemail) </div> <div class="display-label"> @html.displaynamefor(model => model.supportfax) </div> <div class="input-medium"> @html.editorfor(model => model.supportfax) @html.validationmessagefor(model => model.supportfax) </div> <div class="display-label"> @html.displaynamefor(model => model.supportftp) </div> <div class="input-medium"> @html.editorfor(model => model.supportftp) @html.validationmessagefor(model => model.supportftp) </div> </fieldset> <br /> <div class="pull-right"> @if (viewbag.isupdate == true) { <button class="btn btn-primary" type="submit" id="btnupdate" name="command" value ="update">update</button> } else { <button class="btn btn-primary" type="submit" id="btnsave" name="command" value="save">save</button> } <button type="button" id="cancel" class="btn btn-primary" onclick="closemodal()">cancel</button> </div> }
then scrip on parent view:
<script type="text/javascript"> $(document).ready(function () { $(".editdialog").on("click", function (e) { // e.preventdefault(); use or return false var url = $(this).attr('href'); $("#dialog-edit").dialog({ title: 'edit office', autoopen: false, resizable: false, height: 450, width: 380, show: { effect: 'drop', direction: "up" }, modal: true, draggable: true, open: function (event, ui) { $(this).load(url); }, close: function (event, ui) { $("#dialog-edit").dialog().dialog('close'); } }); $("#dialog-edit").dialog('open'); return false; }); }); </script>
what i'm doing wrong ????
inline handlers such onclick="closemodal()"
not set this
inside function being called. have pass this
reference inline:
onclick="closemodal(this)" function closemodal(el) { $(el).dialog("close"); }
or attach handler jquery , set this
reference inside of event handler:
//instead of onclick="", attach handler inside dom ready: $(function() { $('#cancel').click(closemodal); }); function closemodal() { $(this).dialog("close"); }
this assumes #cancel
present when page structure finished rendering , markup valid (no duplicated ids).
Comments
Post a Comment