0

我在视图上有一个LinkButton名为“退出聊天”。我将javascript代码嵌入到OnClientClink=javascript:confirm('Are you sure you want to end the session?')。但是,我无法管理对话框

当用户单击确定按钮时,视图应该被终止。我该怎么做?

<asp:LinkButton ID="LinkButton2" runat="server" Font-
    Bold="False" Font-Underline="False" 
    OnClientClick="javascript:confirm('Are you sure you want to end the session?')"
    ViewStateMode="Enabled" OnClick="LinkButton2_Click1" Text="Exit Chat">
</asp:LinkButton>

我写了这个代码部分但没有工作:(

if (LinkButton2.CommandName=="OK")
{
    MultiView1.ActiveViewIndex = -1;
}
else if(LinkButton2.CommandName=="Cancel")
{
    MultiView1.ActiveViewIndex = 1;
}
4

1 回答 1

0

您可以检查确认的结果,如果为真则关闭窗口。

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
        CommandName="Delete" Text="Delete"
        OnClientClick="return showConfirm();">
</asp:LinkButton>

<script>
function showConfirm()
{
   var ok = confirm('Are you certain you want to delete this product?');

   if (ok)
   {
      window.close();
   }
}
<script>
于 2013-02-01T21:34:32.653 回答