1

I write this script that user check checkbox info that want to delete and click delete button it delete info with ajax. My problem is that when in first time I delete everything is fine but in second time title of dialog is empty. Why?

I do that with this code after showing dialog because my title is dynamic:

$("#ui-id-1").text(tittle);

<script src="../../Scripts/jquery-1.8.3.js"></script>
<script src="../../Scripts/jquery-ui-1.9.2.custom.js"></script>
    <script>
        $(function () {
            $(":checkbox").change(function () {
                var $this = $(this);
                if ($this.is(":checked")) {
                    $this.closest("tr").addClass("SlectedtRow");
                } else {
                    $this.closest("tr").removeClass("SlectedtRow");
                }
            })
            var tittle = '';
            var url = '';
            $("#dialog").dialog({
                autoOpen: false,
                width: 400,
                modal: true,
                resizable: false,
                buttons: [
                    {
                        text: "بلی",
                        click: function () {
                            Delete();
                            $(this).dialog("close");
                        }
                    },
                    {
                        text: "خیر",
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
            var IsActive
            // Link to open the dialog
            $(".insertBtn").click(function (event) {

                var IsSelected = false;
                var ModalText = "  آیا کاربر ";
                $('#userForm input:checked').each(function () {
                    ModalText += this.value + " - "
                    IsSelected = true;

                });

                if (IsSelected) {
                    document.getElementById('ErrorContent').style.display = "none";
                    ModalText = ModalText.slice(0, -2);
                    if (this.id == 'DeleteUser') {
                        ModalText += " حذف گردد  "
                        tittle = 'حذف کاربر'
                        url = '@Url.Action("DeleteUser", "UserManagement")';
                    }
                    else if (this.id == 'InActiveUser') {
                        ModalText += " غیر فعال گردد  "
                        tittle = 'تغییر فعالیت کاربر '
                        url = '@Url.Action("ChangeActiveStatus", "UserManagement")';
                    IsActive = false;
                }
                else if (this.id == 'ActiveUser') {
                    ModalText += "  فعال گردد  "
                    tittle = 'تغییر فعالیت کاربر '
                    url = '@Url.Action("ChangeActiveStatus", "UserManagement")';
                    IsActive = true;
                }
        $('#ModalMessgae').text(ModalText);


        $("#dialog").dialog("open");
        $("#ui-id-1").text(tittle);
        event.preventDefault();

    }        })

            function Delete() {
                var list = [];
                $('#userForm input:checked').each(function () {
                    list.push(this.id);

                });
                var parameters = {};
                if (url == '@Url.Action("DeleteUser", "UserManagement")') {
                parameters = JSON.stringify(list);
            }
            else {
                parameters = JSON.stringify({ "userId": list, "ISActive": IsActive });
            }
            $.ajax({
                url: url,
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: "html",
                traditional: true,
                data: parameters,
                success: function (data, textStatus, jqXHR) {
                    $('#updateAjax').html(data);
                },
                error: function (data) {
                    $('#updateAjax').html(data);

                }
            });   //end ajax
        }
        });
    </script>

html markup

@using Common.UsersManagement.Entities;
@model IEnumerable<VwUser>
@{
    Layout = "~/Views/Shared/Master.cshtml";
}

<form id="userForm">
    <div id="updateAjax">
        @if (string.IsNullOrWhiteSpace(ViewBag.MessageResult) == false)
        {
            <div class="@ViewBag.cssClass">
                @Html.Label(ViewBag.MessageResult as string)
            </div>
            <br />
        }
        <table class="table" cellspacing="0">
            @foreach (VwUser Item in Model)
            {   
                <tr class="@(Item.IsActive ? "tRow" : "Disable-tRow")">
                    <td class="tbody">
                        <input type="checkbox" id="@Item.Id" name="selected"  value="@Item.FullName"/></td>
                    <td class="tbody">@Item.FullName</td>
                    <td class="tbody">@Item.Post</td>
                    <td class="tbody">@Item.Education</td>
                </tr>
            }
        </table>
    </div>
    <br />
    <br />
@if (!Request.IsAjaxRequest())
{
    <div class="btnContainer">
        <a href="#" id="DeleteUser" class="insertBtn">delete  </a>
        <br />
        <br />
    </div>}

1 Answer 1

1

set title like below

Specifies the title of the dialog. If the value is null, the title attribute on the dialog source element will be used.

Code examples:

Initialize the dialog with the title option specified:

$( ".selector" ).dialog({ title: "Dialog Title" });
//Get or set the title option, after initialization:
// getter
var title = $( ".selector" ).dialog( "option", "title" );

// setter
$( ".selector" ).dialog( "option", "title", "Dialog Title" );

see set title in dialog box

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.