Move this topic
How can I select the specific button on the dialog box then give it a close event?
in Using jQuery Plugins
•
8 years ago
Hi, I have a dialog box that shows a partial MVC view. The dialog box does not close when I click on the close button. It does close if I hit the escape key or click on the x at the top right of the box.
I’ve seen a lot of examples out there but nothing has worked for me so far. How can I select the specific button on the box then give it a close event?
Here’s my code so far:
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#my-dialog').dialog({
autoOpen: false,
width: 700,
height: 600,
title: "Schedule",
resizable: false,
modal: false,
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$('.modal').click(function () {
$('#my-dialog').load(this.href, function () {
$(this).dialog('open');
});
return false;
});
});
});
</script>
1
Replies(7)
What you have works for me.
BTW, you don't need both $(document).ready(function() { and $(function() { as they are the same thing.
BTW, you don't need both $(document).ready(function() { and $(function() { as they are the same thing.
Leave a comment on kbwood.au's reply
Yes it works for me if I don't load a partial view with an ActionLink. Sorry I didn't post this to begin with. The link that loads my partial view and causes the box to show is like this:
<div id="instructorSidebarDiv" >
@Html.ActionLink("My Schedule", "GetSchedule","Schedule", new { tester = 3 }, new { @class = "modal" })
</div>
It seems like this process makes the button's code out of scope somehow.
Leave a comment on spottedtowhee's reply
Can you provide a page that shows the problem?
Leave a comment on kbwood.au's reply
This
is the view that calls the dialog box which houses the partial view.
@model SchoolIn.ViewModels.InstructorIndexData
@using
SchoolIn.Models
@{
ViewBag.Title = "AllAttendance";
}
<h2>All
Attendance </h2>
<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>
<link href="../../Content/dataTable/the_table.css" rel="Stylesheet"
type="text/css"
/>
<script src="../../Scripts/DataTables-1.9.1/media/js/jquery.dataTables.js"
type ="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js"
type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js"
type="text/javascript"></script>
<script src="../../Scripts/GradeValidation.js"
type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"
rel="stylesheet"
type="text/css"
/>
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"
type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function
() {
$(function
() {
$(".datepicker").datepicker({
dateFormat: 'mm.dd.yy' });
$("#dropdownselected1").val($("#categories").val());
});
var
dialogButton;
$(function
() {
$('#my-dialog').dialog({
autoOpen: false,
width: 700,
height: 600,
title: "Schedule",
resizable: false,
modal: false,
buttons: {
"Close":
function () {
$(this).dialog("close");
}
}
});
$('.modal').click(function () {
$('#my-dialog').load(this.href, function
() {
$(this).dialog('open');
});
return
false;
});
});
});
</script>
<p>
@Html.ActionLink("Create
New", "Create")
</p>
<table id="
allAttendanceMainTable" style ="width:100%">
<td id="instructorLeftCell" style ="width:20%;vertical-align:top">
<div id="instructorSidebarDiv" style ="top"><table id="instructorSideBarTable" style ="vertical-align:top"><td style ="vertical-align:top"><tr>
@Html.ActionLink("My
Schedule", "GetSchedule","Schedule", new
{ tester = 3 }, new { @class = "modal" })<br />
@Html.ActionLink("Today's
Attendance", "Index", "Attendance", new
{ id = 3, courseID = 1005, teacher ="Tom
Dewey", course = "Geometry",
category="Engineering" }, null)</tr></td></table></div>
</td>
<td id="instructorRightCell" style ="width :80%">
<table id="allAttendanceTable_1">
<tr>
<th>Reports</th>
<th>Quick View</th>
<th>First Name</th>
<th>Last Name</th>
<th>Class</th>
<th id="allAttendanceGradeHead" style="border-color:Black">Grade</th>
<th>Attendance
Code</th>
<th id=classDayHead>Class Day</th>
<th>Assignment
Type</th>
<th>Overall Grade</th>
</tr>
@foreach (var item in
Model.Enrollments)
{
Leave a comment on spottedtowhee's reply
Then the partial view that is loaded into the dialog box...
@model SchoolIn.ViewModels.ScheduleData
@{Layout = null;}
@{
ViewBag.Title = "Index";
}
<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>
<link href="../../Content/dataTable/the_table.css" rel="Stylesheet" type="text/css" />
<script src="../../Scripts/DataTables-1.9.1/media/js/jquery.dataTables.js" type ="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<script src="../../Scripts/GradeValidation.js" type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js" type="text/javascript"></script>
@{ Html.EnableClientValidation(); }
@if (Model.Enrollments != null)
{
<table>
<tr>
<th>
Course
</th>
<th>
Class Day
</th>
<th>
Class Time
</th>
<th></th>
</tr>
@foreach (var item in Model.Enrollments)
{
<tr>
<td>
@{
int hh = item.CourseID;
string iInstructorId = (from x in Model.Courses where x.CourseID == hh select x.Title).Single();
@iInstructorId
}
</td>
<td>
@Html.DisplayFor(modelItem => item.classDays)
</td>
<td>
@Html.DisplayFor(modelItem => item.timeOfClass)
</td>
</tr>
}
</table>
}
<button id="closeButton">Close Partial</button>
Leave a comment on spottedtowhee's reply
Can you provide live HTML instead of source ASP?
Leave a comment on kbwood.au's reply
I used F12 in FireFox...
<!DOCTYPE html>
<html class="
js flexbox canvas canvastext webgl touch geolocation postmessage
no-websqldatabase indexeddb hashchange history draganddrop websockets
rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow
textshadow opacity cssanimations csscolumns cssgradients
no-cssreflections csstransforms csstransforms3d csstransitions fontface
video audio localstorage sessionstorage webworkers applicationcache svg
inlinesvg smil svgclippaths">
<head>
<meta charset="utf-8">
<title>AllAttendance</title>
<link type="text/css" rel="Stylesheet" href="../../Content/themes/base/jquery.ui.all.css">
<script type="text/javascript" src="../../Scripts/DataTables-1.9.1/media/js/jquery.js">
<link type="text/css" rel="stylesheet" href="/Content/Site.css">
<script type="text/javascript" src="/Scripts/modernizr-1.7.min.js">
<script type="text/javascript" src="../../Scripts/jquery.ui.core.js">
<script type="text/javascript" src="../../Scripts/jquery.ui.datepicker.js">
<link type="text/css" rel="Stylesheet" href="../../Content/themes/base/jquery.ui.core.css">
<link type="text/css" rel="Stylesheet" )"="" href="../../Content/themes/base/jquery.ui.datepicker.css">
<link type="text/css" rel="Stylesheet" href="../../Content/themes/base/jquery.ui.theme.css">
<script type="text/javascript" src="../../Scripts/DatePickerReady.js">
</head>
<body>
<div class="page">
<header>
<div id="title">
<br>
<br>
<br>
<nav>
</header>
<section id="main">
<footer ;="" style="background-color:#d4edfc">
A better way to manage data
</footer>
</div>
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ui-dialog-buttons ui-draggable" style="height: auto; width: 700px; top: 84px; left: 366px; display: none;" tabindex="-1" role="dialog" aria-describedby="my-dialog" aria-labelledby="ui-id-1">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-id-1" class="ui-dialog-title">Schedule</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" type="button" role="button" aria-disabled="false" title="close">
<span class="ui-button-icon-primary ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">close</span>
</button>
</div>
<div id="my-dialog" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; max-height: none; height: 471px;">
<script type="text/javascript" src="/Scripts/jquery.validate.min.js">
<script type="text/javascript" src="/Scripts/jquery.validate.unobtrusive.min.js">
<link type="text/css" rel="Stylesheet" href="../../Content/dataTable/the_table.css">
<script type="text/javascript" src="../../Scripts/DataTables-1.9.1/media/js/jquery.dataTables.js">
<script type="text/javascript" src="../../Scripts/MicrosoftAjax.js">
<script type="text/javascript" src="../../Scripts/MicrosoftMvcValidation.js">
<script type="text/javascript" src="../../Scripts/GradeValidation.js">
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js">
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js">
pt>
<table>
<div id="myBig-dialog"> and the contentents on local page</div>
<button id="closeButton">Close this thing</button>
</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button" aria-disabled="false">
<span class="ui-button-text">Close</span>
</button>
</div>
</div>
</div>
</body>
</html>
Leave a comment on spottedtowhee's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic
Reply to spottedtowhee's question
Statistics
- 7 Replies
- 6987 Views
- 0 Followers

