I'm having a problem opening a JQuery Dialog from C# codebehind. It works on other pages I did, but on this one it's not working. I've already tried this, this, this and this. But I'm missing something.
Basically, there's a table with a GridView on the left and a counter with image buttons on the right. What I'm trying to do is to show a dialog to the user to confirm if he wants to reset the counter when Stop button (btnZerar) is clicked.
I put a breakpoint on #StopDialogConfirm and it's only reached when the page is loaded, but it's not reached when the button is clicked. There's no javascript error.
Follow my code samples:
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 - code commented out are things I have tried. When I try to open an alert, it works.
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?");
}
Script (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();
}
}
});
});
Please, help! Thanks!