[英]Jquery Dialog is not firing when call from the C# code behind
这是我的.aspx:
<div id="divAddrCandidates" class="selector" style="display:none">
<div style="margin-left:10px ; margin-top:10px">
<asp:ListBox ID="lstCandidates" runat="server" ></asp:ListBox>
</div>
<br />
<div style="margin-left:10px">
<asp:Button ID="btnSelect" runat="server" Text="Select Address" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" onclientclick="CloseAddrCandidatesWin(); return false;" />
</div>
</div>
这个jQuery:
function OpenAddrCandidatesWin() {
$("#divAddrCandidates").dialog({
resizable: true,
width: 650,
heigh: 450,
modal: true,
draggable: true,
resizable: true
});
$(".selector").dialog({ dialogClass: 'no-close' });
jQuery("#divAddrCandidates").parent().appendTo(jQuery("form:first"));
}
function CloseAddrCandidatesWin() {
$("#<%=lstCandidates.ClientID %>").val("");
$("#<%=lstCandidates.ClientID %>").hide();
$("#divAddrCandidates").dialog("close");
}
这是我的代码背后:
protected void Save_Click(object sender, System.EventArgs e)
{
JsonAddresses = WSJson.GetAddressCandidate(physicalAddrToProcess);
int count = JsonAddresses.candidates.Length;
for (int i = 0; i < count; i++)
{
lstCandidates.Items.Add(JsonAddresses.candidates[i].address.ToString());
}
string key = "_OpenAddrCandidatesWin";
string script = "OpenAddrCandidatesWin();";
if (!Page.ClientScript.IsStartupScriptRegistered(key))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), key, script, true);
}
}
我在这里想念什么? 尽管我在jquery处设置了一个中断,但代码没有错误地通过,但对话框没有弹出,但是它从未停止过。 任何帮助,将不胜感激。
可能是因为您在加载dom之前就正在执行该方法。
尝试更改string script = "OpenAddrCandidatesWin();";
string script = "$(function () { OpenAddrCandidatesWin(); })";
它将等到dom加载后再执行该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.