JQueryUI 对话框在 JS 文件中不起作用
我有进行 Ajax 调用的 JQuery 代码,为了重用相同的代码,我将代码放在 .JS 文件中。
这是场景。
1)我的aspx页面中有超链接控件和div控件。 div 控件用于显示 JQueryUI 对话框消息。
2) 我有 JS 文件,它接收超链接对象和 div 对象的引用
3) 在 JS 文件中,我通过 JQuery Ajax 插入记录,它运行良好,但问题是它没有显示 JQuery UI 对话框
代码
Aspx 文件
<asp:HyperLink ID="hlInsertRecord" runat="server" Text="Insert Record" Font-Bold="true" />
<div id="pnlInsertRecordMsg" title="Insert Record"></div>
在 Aspx.cs 文件中(javascript 函数的绑定引用)
string strInsertRecord = "InsertRecord(" + hlInsertRecord.ClientID + ",pnlInsertRecordMsg);return false;";
hlInsertRecord.Attributes.Add("onclick", strInsertRecord);
请注意:autoOpen:true 并且我已通过取消注释打开对话框来检查我的代码 在 .JS 文件中
function InsertRecord(hlInsertRecord, pnlInsertRecordMsg) {
$(document).ready(function () {
//--------Message Box Start-------------------
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 900;
$(function () {
$(pnlInsertRecordMsg.id).dialog({
autoOpen: true,
resizable: false,
show: "highlight",
hide: "fade"
});
// $(hlInsertRecord.id).click(function () {
// $(pnlInsertRecordMsg.id).dialog("open");
// return false;
// });
});
//--------Message Box End-------------------
pnlInsertRecordMsg.innerHTML = "Please wait, we are sending your request...";
$.ajax({
type: "POST",
url: hlInsertRecord.href,
success: OnInsertRecordSuccess,
error: OnInsertRecordFail
});
//});
function OnInsertRecordSuccess(response) {
hlInsertRecord.innerHTML = "Record Inserted";
pnlInsertRecordMsg.innerHTML = response;
setTimeout(function () { $(pnlInsertRecordMsg.id).dialog("close"); }, 2000);
}
function OnInsertRecordFail(response) {
pnlInsertRecordMsg.innerHTML = "Oops we are unable to send your request. Please try again!!!";
setTimeout(function () { $(pnlInsertRecordMsg.id).dialog("close"); }, 10000);
}
});
}
I have JQuery code which makes Ajax call, In order to reuse same code, I have put my code in .JS File.
Here is the scenario.
1) I have hyperlink control and div control in my aspx page. div control is for displaying JQueryUI dialog message.
2) I have JS file which receives reference of hyperlink object and div object
3) In JS file i am insert record through JQuery Ajax, it is working good, but problem is it is not displaying JQuery UI Dialog
Code for that
In Aspx File
<asp:HyperLink ID="hlInsertRecord" runat="server" Text="Insert Record" Font-Bold="true" />
<div id="pnlInsertRecordMsg" title="Insert Record"></div>
In Aspx.cs File (Binding reference of javascript function)
string strInsertRecord = "InsertRecord(" + hlInsertRecord.ClientID + ",pnlInsertRecordMsg);return false;";
hlInsertRecord.Attributes.Add("onclick", strInsertRecord);
Please note: autoOpen:true and i have check my code with uncommenting open dialog
In .JS File
function InsertRecord(hlInsertRecord, pnlInsertRecordMsg) {
$(document).ready(function () {
//--------Message Box Start-------------------
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 900;
$(function () {
$(pnlInsertRecordMsg.id).dialog({
autoOpen: true,
resizable: false,
show: "highlight",
hide: "fade"
});
// $(hlInsertRecord.id).click(function () {
// $(pnlInsertRecordMsg.id).dialog("open");
// return false;
// });
});
//--------Message Box End-------------------
pnlInsertRecordMsg.innerHTML = "Please wait, we are sending your request...";
$.ajax({
type: "POST",
url: hlInsertRecord.href,
success: OnInsertRecordSuccess,
error: OnInsertRecordFail
});
//});
function OnInsertRecordSuccess(response) {
hlInsertRecord.innerHTML = "Record Inserted";
pnlInsertRecordMsg.innerHTML = response;
setTimeout(function () { $(pnlInsertRecordMsg.id).dialog("close"); }, 2000);
}
function OnInsertRecordFail(response) {
pnlInsertRecordMsg.innerHTML = "Oops we are unable to send your request. Please try again!!!";
setTimeout(function () { $(pnlInsertRecordMsg.id).dialog("close"); }, 10000);
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白你为什么使用这个 $(pnlInsertRecordMsg.id)
我认为这里应该 $('#pnlInsertRecordMsg').dialog
如果我错了,请纠正我。
I am not getting why you use this $(pnlInsertRecordMsg.id)
I think here should $('#pnlInsertRecordMsg').dialog
If i am wrong then correct me.