0
我有使Ajax调用的JQuery代码,为了重用相同的代码,我将代码放在了.JS文件中。JQueryUI对话框不能在JS文件中工作
这是场景。
1)我的aspx页面中有超链接控件和div控件。 div控件用于显示JQueryUI对话框消息。
2)我有一个接收超链接对象和DIV对象
3)在JS文件我是通过JQuery的阿贾克斯插入记录的参考,这是工作好JS文件,但问题是,它没有显示JQuery用户界面对话
代码为
在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:如此,我检查我的代码在取消打开对话框 在.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);
}
});
}
$(pnlInsertRecordMsg.id).dialog ..你在这里得到正确的对话框ID吗? – Priyank
是的,我得到正确的ID –