<div id="dialog"></div>
<table>
<tr>
<td style="text-align: right">
#Html.ActionLink("Craete New Set1", "CreateNewSet1", "ClaimAuditAdmin", null, new{ #class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Create New Claim Audit Set"})
</td>
<td>
</td>
</tr>
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
// $(".divContainer")
// $("<div></div>")
$("#dialog")
// .addClass("dialog")
.attr("id", $(this).attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true,
height: 325,
width: 325,
draggable: true,
resizable: false,
position: 'center',
scrollable:false
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
Jquery PopUp in MVC showing in Chrome but not in IE.Also No issues showing in IE.
Try this once, Basically, you 'load' the content from the other page first.
$("#dialog")
.load(this.href)
.dialog({
autoOpen: false
}).open();
or
var link = this.href;
$("#dialog")
.dialog({
open: function (event, ui) {
$(this).load(link);
},
});
Related
Pretty new to ajax.
So I have this div:
<div id="authentication" title="Authentication" >
<b>Please Generate a new token to continue!</b>
<br /><br />
<table>
<tr>
<td>Token:</td>
<td><input type="text" id="txtToken"/></td>
</tr>
<tr>
<td></td>
<td><label id="lblError"></label></td>
</tr>
</table>
</div>
which is not being displayed on my mvc view because it is a being used as a dialogue box by Ajax code below:
$('#authentication').dialog({
autoOpen: true,
width:500,
resizable: false,
beforeclose : function() { return false; },
title: 'Authentication',
modal: true,
buttons: {
"Cancel": function () {
window.location.replace("#Url.Action("Index", "Home")");
},
"Submit": function () {
var token=$('#txtToken').val();
var dlg = $(this);
$.ajax({
type: 'POST',
data: { 'token': token},
dataType: 'json',
url: '#Url.Action("CheckNewToken", "Account")',
success: function (result) {
if(result==true)
{
window.parent.jQuery('#authentication').dialog('destroy');
}
else{
$('#lblError').html("Incorrect credentials. Please try again");
}
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
}
}
});
However when the codes goes to success and result == result, the dialog box is destroyed but the div (dialog box) is then being displayed on my view which I don't want. What am I doing wrong?
Close the dialog and then destroy. This will hide the dialog completely and then destroy its dialog features. if you just do .dialog('destroy') it will just remove the dialog functionality completely and display the element as is on the page but it wont hide.
success: function (result) {
if(result==true)
{
$('#authentication').dialog('close').dialog('destroy');
}
else{
$('#lblError').html("Incorrect credentials. Please try again");
}
},
Another thing is beforeclose : function() { return false; }, you are returning false which will prevent the close event from happening. it should be beforeClose though you can remove it safely.
if the above doesnt work another option to remove the div is by subscribing to close event:-
$('#authentication').dialog({
autoOpen: true,
width:500,
resizable: false,
title: 'Authentication',
modal: true,
close:function(){
$(this).dialog('destroy').hide();
},
buttons: {
"Cancel": function () {
},
"Submit": function () {
var token=$('#txtToken').val();
var dlg = $(this);
$('#authentication').dialog('close');
}
}
});
There are several posts on StackOverflow on the subject but none of the answers helped me.
I am using the DataList control that is populated by a SELECT through a DataAdapter.
A concept is recommended that only one instance of the dialog must be open but could not apply this method
The structure of the html is:
<asp:DataList ID="DataList" runat="server">
<ItemStyle />
<ItemTemplate>
<a href="" class="link"/></a>
<div class = "dialog" id="dynamicID" style="display:none">
</ div>
</ ItemTemplate>
</ asp: DataList>
The jQuery code I'm using is:
<script language="javascript" type="text/javascript">
$ (function () {
$ (". link. ") click (function () {
var id = '#' + ($ (this). siblings ('. dialog'). attr ('id'));
$ (id). dialog ({
AutoOpen: false,
closeOnEscape: true,
resizable: false,
draggable: false,
modal: true,
width: 800,
height: 600,
overlay: {backgroundColor: "# 000", opacity: 0.5},
top: 20,
show: 'fade',
hide: 'fade',
buttons: {
"Close": function () {
$ (id). dialog ('close');
}
}
});
$ (id). dialog ('open');
});
});
</ script>
Imagine this HTML
<asp:DataList ID="dataList" runat="server">
<ItemTemplate>
<div class="row">
<p>
Result: <strong>
<%# Container.DataItem.ToString() %></strong></p>
<a href="#" class="link" data-open="dialog_<%# Container.ItemIndex %>" />Click
To Open</a>
<div class="dialog" id="dialog_<%# Container.ItemIndex %>">
<h2>
This is the text inside the dialog #
<%# Container.ItemIndex %>.</h2>
<p>
</p>
</div>
</div>
</ItemTemplate>
</asp:DataList>
with this javascript
$(function () {
// create dialogs
$(".dialog").dialog({
autoOpen: false,
closeOnEscape: true,
buttons: {
"Close": function () {
$(id).dialog('close');
}
}
});
// hook up the click event
$(".link").bind("click", function () {
// console.log($(this).parent());
// open the dialog
var dialogId = $(this).attr("data-open");
$("#" + dialogId).dialog("open");
return false;
});
});
works lovely.
Working example can be found here
What is wrong with your approach?
you are creating the dialog's inside a method, and this should be created inside the $(document).ready() so, everytime you click, it creates a dialog, but... it already exists and screws up everything.
When working with dialogs:
First you create them using .dialog()
You just need to use .dialog('open') to make that dialog visible
And use .dialog('close') to hide that dialog
by default jQuery UI CSS will hive the dialogs automatically (display:none;) so you don't need to do anything like that.
Usually just destroying the dialog on close will fix the issue.
$( "#dialogbox" ).dialog({
close: function (event, ui) {
$(this).dialog("destroy");
}
});
When dialog has displayed it fall out from the markup flow. So when you call var id = '#' + ($ (this).siblings('.dialog').attr('id')); you don't get anything. You can add dialog's id to array first time it opens and then if $(this).siblings ('.dialog') result is empty you may get dialog element id from array.
<script type="text/javascript">
var registeredDialogs = [];
function registerDialog(link, dialogDiv) {
var linkId = $(link).attr("id");
if (!registeredDialogs[linkId])
registeredDialogs[linkId] = dialogDiv;
}
function getDialog(link) {
var linkId = $(link).attr("id");
return this.registeredDialogs[linkId];
}
$(function () {
$(".link").click(function () {
var dialogDiv = $(this).siblings('.dialog');
if (dialogDiv.length !== 0) {
registerDialog(link, dialogDiv);
}
else {
dialogDiv = this.getDialog(link);
}
dialogDiv.dialog({
AutoOpen: false,
closeOnEscape: true,
resizable: false,
draggable: false,
modal: true,
width: 800,
height: 600,
overlay: { backgroundColor: "# 000", opacity: 0.5 },
top: 20,
show: 'fade',
hide: 'fade',
buttons: {
"Close": function () {
$(id).dialog('close');
}
}
});
$(id).dialog('open');
});
});
</script>
Hi
I am using jquery dialog box,and when I am selecting a record from atable, it call the dialog box, then when I close it and chose another record, it opens the old dialog with the new dialog... what is the problem
$(document).ready(function () {
$("#btnenterpat").click(function () {
$("#enter_payment").dialog('open');
});
$("#enter_payment").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 400,
height: 300,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
ok: function () {
retur_dialog = 'ok';
$(this).dialog('close');
},
},
beforeClose: function () {
if (retur_dialog == 'ok') {
$.ajax({
url: 'ssssssss.php',
data: {
pm1: $("#pm1").val(),
pm2: $("#pm2").val(),
pm3: $("#pm3").val(),
pm4: $("#pm4").val(),
pm5: $("#pm5").val(),
pm6: $("#pm6").val(),
pm7: $("#pm7").val(),
},
});
}
}
});
});
EDIT:
First page:
<?php
include ("angela_test.php")
?>
<div style="font-size:12px;">
</div>
<br />
<table id="tbl_angela_test_data"></table>
<div id="p_angela_test_data"></div>
<script type="text/javascript">
$(document).ready(function(){
var selected_id;
var colCap = Array();
var colDef = Array();
var grp_filter = 0;
$.ajax({
url: "getColDefs.php" ,
data: {table: "bk_accounts", userid: "5", groupid: "1"},
dataType: "json",
async: false,
success: function (data) {
colCap = data[0];
colDef = data[1];
}
});
var cols = '';
for(i=0; i<colDef.length; i++) {
cols += colDef[i].name;
if (i != (colDef.length-1)) {
cols += ';';
}
}
jQuery("#tbl_angela_test_data").jqGrid({
url:'admin/angela_test_table_get.php',
postData: {columns: cols},
datatype: 'json',
mtype: 'POST',
height: 'auto',
width: 'auto',
rowNum: 20,
rowList: [10,20,30],
colNames: colCap,
colModel: colDef,
pager: "#p_angela_test_data",
viewrecords: true,
toolbar: [true, 'both'],
caption: "angela_test",
onSelectRow: function(id){
selected_id = id;
$("#angela_test_del_bnt, #angela_test_edit_bnt").attr("disabled", false);
}
});
jQuery("#tbl_angela_test_data").setGridWidth(500);
$("#t_tbl_angela_test_data").height(40);
$("#t_tbl_angela_test_data").append('<button id="angela_test_edit_bnt" style="height:30px; width:100px;" disabled="true">Edit</button>');
// edit button
$("#angela_test_edit_bnt").click(function(){
var rw = '#angela_test_item_'+selected_id;
var maintab = $("#tabs");
if ($(rw).html() != null) {
maintab.tabs('select',rw);
} else {
maintab.tabs('add',rw,'Edit form');
$(rw, '#tabs').load('admin/angelatest.php?id='+selected_id);
}
});
//////////////////////////////
})
</script>
and the second page is:
<?php
include_once("angela_test.php");
?>
<input type="button" id="btnenterpat" value="Enter Payment">
and the dialog code is:
<script type="text/javascript">
$(document).ready(function () {
$("#btnenterpat").click(function () {
$("#angela_test").dialog('open');
});
$("#angela_test").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 400,
height: 300,
buttons: {
Cancel: function () {
$(this).dialog('close');
},
ok: function () {
$(this).dialog('close');
},
},
}).parent().find(".ui-dialog-titlebar-close").hide();
});
</script>
<!--Enter Payment windows -->
<div id="angela_test" ></div>
<!--dialog windows end -->
Calling $('#some-div').dialog('destroy') would restore the #some-div element to its original form before calling $('#some-div').dialog(...). Maybe you can consider doing that upon closing the dialog?
I open modal dialog twice,
the textbox is locked in the first dialog(parent dialog) after the second dialog closed
Why? How to resolve the problem? I am new user,so I can't post the image
Any answer will be appreciated, thank you
Html:
<XMP>
<input id="btnDlg" type="button" value="open dialog" />
<div id="dlg1"><%=Html.TextBox("txtName","can not edit") %><input id="btnShowDlg" type="button" value="dialog again" /></div>
<div id="dlg2"><div>the second dialog</div><%=Html.TextBox("txtName2") %></div>
</XMP>
jquery:
$("#dlg1").dialog({
autoOpen: false,
height: 350,
width: 300,
title: "The first dialog!",
bgiframe: true,
modal: true,
resizable: false,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'OK': function() {
$(this).dialog('close');
}
}
})
$("#dlg2").dialog({
autoOpen: false,
height: 200,
width: 300,
title: "This is the second dialog!",
bgiframe: true,
modal: true,
resizable: false,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'OK': function() {
$(this).dialog('close');
}
}
})
$("#btnDlg").click(function() {
$("#dlg1").dialog("open");
})
$("#btnShowDlg").click(function() {
$("#dlg2").dialog("open");
})
buttons: {
"Save": function () {
//validate
if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate(newValGroup);
}
if (Page_IsValid) {
gettHTML(divID, PriceID);
}
},
Cancel: function () {
$(this).dialog("close");
}
},
close: function (ev, ui) {
$(this).dialog("destroy");
}
});
$("#" + divID).dialog('open');
return false;
Yes divid can you try Making Modal : false. it will work..
let me know..
Thanks
I have a table and within the first <td> is a hidden <div>. I want to show the div using a jQuery ui dialog which I have the following code
example tr
<tr>
<td>
<div id="subscriberNote" style="display: none;">
long message text........
</div>
long mess...
</td>
<td>
<a id="notedetails" href="#">View note</a>
</td>
</tr>
jQuery
function subscriberNotes_onload() {
$("#subscriber_notes tr").bind("click", function() {
openDialog(this);
});
}
function openDialog(row){
$(row).closest("tr").find("td:eq(0)").find("#subscriberNote").dialog({
title: "Message",
modal: true,
width: 600,
height: 530,
buttons: {
"OK": function () { $(this).dialog("close"); }
}
}).show();
}
After the dialog is shown and closed it is removing the hidden div and so has nothing to show until the page is refreshed.
Make the last function like:
function openDialog(row){
$(row).closest("tr").find("td:eq(0)").find("#subscriberNote").dialog({
title: "Message",
modal: true,
width: 600,
height: 530,
buttons: {
"OK": function () { $(this).dialog("close"); }
},
close: function(){ $(this).dialog("destroy")}
}).show();
}
According to the docs it should revert to its original state.