【发布时间】:2013-12-28 18:56:11
【问题描述】:
我在从 C# 代码隐藏打开 JQuery 对话框时遇到问题。它适用于我所做的其他页面,但在这个页面上它不起作用。 我已经尝试过this、this、this 和this。但我错过了一些东西。
基本上,左侧有一个带有 GridView 的表格,右侧有一个带有图像按钮的计数器。我要做的是向用户显示一个对话框,以确认他是否要在单击停止按钮 (btnZerar) 时重置计数器。
我在#StopDialogConfirm 上设置了一个断点,它仅在页面加载时到达,但在单击按钮时未到达。没有 javascript 错误。
按照我的代码示例:
ASPX:
<asp:Content ID="scriptsHeader" ContentPlaceHolderID="FeaturedContent" runat="server">
<script type="text/javascript" src="/Scripts/Pages/EstudeCiclos.js"></script>
<script type="text/javascript" src="/Scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/Scripts/jquery-ui-1.8.20.min.js"></script>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="updPanelEstudeCiclos" UpdateMode="Conditional" runat="server"> <ContentTemplate>
...
<div>
<asp:ImageButton ID="btnPlay" runat="server" OnClick="btnPlayClick" ImageUrl="~/Images/play.jpg" Height="40px" Width="40px" AlternateText="Começar a contar o tempo" />
<asp:ImageButton ID="btnPause" runat="server" OnClick="btnPauseClick" ImageUrl="~/Images/pause.jpg" Height="40px" Width="40px" AlternateText="Parar tempo" />
<asp:ImageButton ID="btnZerar" runat="server" OnClick="btnZerarClick" ImageUrl="~/Images/stop.jpg" Height="40px" Width="40px" AlternateText="Zerar tempo" />
<asp:ImageButton ID="btnSalvar" runat="server" OnClick="btnSalvarClick" ImageUrl="~/Images/save.jpg" Height="40px" Width="40px" AlternateText="Salvar tempo" />
</div>
...
<div>
<asp:Button ID="btnStop" runat="server" OnClick="btnStop_Click" Style="display: none;" ClientIDMode="Static" />
</div>
</ContentTemplate> </asp:UpdatePanel>
CodeBehind - 注释掉的代码是我尝试过的。当我尝试打开警报时,它会起作用。
private void OpenQuestionDialog(string functionName, string question)
{
string s = "$(function(){$('#" + functionName + "').dialog('open').text('" + question + "');});";
//ScriptManager.RegisterStartupScript(Page, this.GetType(), "Dialog", s, true);
ScriptManager requestSM = ScriptManager.GetCurrent(this);
if (requestSM != null && requestSM.IsInAsyncPostBack)
{
ScriptManager.RegisterClientScriptBlock(this,
typeof(Page),
Guid.NewGuid().ToString(),
s,
true);
}
else
{
ClientScript.RegisterClientScriptBlock(typeof(Page),
Guid.NewGuid().ToString(),
s,
true);
}
}
protected void btnZerarClick(object sender, EventArgs e)
{
OpenQuestionDialog("StopDialogConfirm", "Are you sure you want to reset the counter?");
}
脚本(EstudeCiclos.js):
$(function () {
$('#StopDialogConfirm').dialog({
autoOpen: false,
width: 450,
modal: true,
buttons: {
"Não": function ()
{
$(this).dialog("close");
},
"Sim": function ()
{
$(this).dialog("close");
$('#btnStop').click();
}
}
});
});
请帮忙!谢谢!
【问题讨论】:
-
有jQuery冲突吗?
-
您在 .ASP 的哪个位置创建了
#StopDialogConfirm元素? -
您好,欢迎来到 Stack Overflow @Andre。您能否仅提供代码的相关部分以提供该问题的简短、独立的示例?
-
@adeneo 我没有在任何地方创建它,它只是在 javascript 文件中。
-
@Bagavatu 抱歉,我编辑了 aspx 代码,现在它变小了。
标签: c# javascript jquery asp.net dialog