asp.net 中服务器端的确认框

发布于 2024-10-19 02:11:34 字数 384 浏览 6 评论 0原文

我想从服务器端显示 ASP.NET 中的确认框:

我想从服务器端调用它,因为我必须从服务器端获取客户消息。我正在使用下面的代码

    string str = "Are you sure, you want to Approve this Record?";
        ClientScript.RegisterStartupScript(typeof(Page), "Popup", "return confirm('" + str + "');",true);
// More code ....

现在它显示弹出窗口,无论我单击什么,无论是“确定”还是“取消”,我的代码都正在执行。

请让我知道当用户在确认框中选择“取消”时如何限制执行代码。

I want to show the confirmation box in asp.net from server side:

I want to call it from server side because I have to take the customer message from server side. I am using the below code

    string str = "Are you sure, you want to Approve this Record?";
        ClientScript.RegisterStartupScript(typeof(Page), "Popup", "return confirm('" + str + "');",true);
// More code ....

Now it is showing the popup and irrespective of what I click, whether "ok" or "Cancel", my code is executing.

Please let me know how can I restrict code to be executed when user select "cancel" in the confirmation box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-10-26 02:11:34

检查一下:

背后代码:

string str = "Are you sure, you want to Approve this Record?";
        this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);

ASPX:

function ConfirmApproval(objMsg)
    {
        if(confirm(objMsg))
        {
            alert("execute code.");
            return true;
        }    
        else
            return false;    
    }

Check it out:

CODE BEHIND:

string str = "Are you sure, you want to Approve this Record?";
        this.ClientScript.RegisterStartupScript(typeof(Page), "Popup", "ConfirmApproval('" + str + "');", true);

ASPX:

function ConfirmApproval(objMsg)
    {
        if(confirm(objMsg))
        {
            alert("execute code.");
            return true;
        }    
        else
            return false;    
    }
情归归情 2024-10-26 02:11:34

检查以下示例代码。

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnOK" runat="server" Text="OK" onclick="btnOK_Click" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lblID" PopupControlID="pnlConfirmation">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlConfirmation" runat="server" Style="background-color: #D4D0C8;
    border: 2px solid black; width: 300px; height: 100px;">
    <asp:Label ID="lblID" runat="server"></asp:Label>
    <table cellpadding="2" cellspacing="2" width="100%">
        <tr>
            <td>
                Your confirmation message here.
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnOK1" runat="server" Text="OK" onclick="btnOK1_Click" /> <asp:Button ID="btncancel"
                    runat="server" Text="Cancel" onclick="btncancel_Click" />
            </td>
        </tr>
    </table>
</asp:Panel>

在服务器端......

protected void btnOK_Click(object sender, EventArgs e)
{
    //some code here.
    //then show modal popup
    ModalPopupExtender1.Show();
}
protected void btnOK1_Click(object sender, EventArgs e)
{
    //If ok some code here to execute
    ModalPopupExtender1.Hide();
}
protected void btncancel_Click(object sender, EventArgs e)
{
    //hide modal popup
    ModalPopupExtender1.Hide();
}

http://forums .asp.net/t/1499789.aspx?确认+弹出+来自+服务器+端

check following example code.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="btnOK" runat="server" Text="OK" onclick="btnOK_Click" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lblID" PopupControlID="pnlConfirmation">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlConfirmation" runat="server" Style="background-color: #D4D0C8;
    border: 2px solid black; width: 300px; height: 100px;">
    <asp:Label ID="lblID" runat="server"></asp:Label>
    <table cellpadding="2" cellspacing="2" width="100%">
        <tr>
            <td>
                Your confirmation message here.
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:Button ID="btnOK1" runat="server" Text="OK" onclick="btnOK1_Click" /> <asp:Button ID="btncancel"
                    runat="server" Text="Cancel" onclick="btncancel_Click" />
            </td>
        </tr>
    </table>
</asp:Panel>

On server side.....

protected void btnOK_Click(object sender, EventArgs e)
{
    //some code here.
    //then show modal popup
    ModalPopupExtender1.Show();
}
protected void btnOK1_Click(object sender, EventArgs e)
{
    //If ok some code here to execute
    ModalPopupExtender1.Hide();
}
protected void btncancel_Click(object sender, EventArgs e)
{
    //hide modal popup
    ModalPopupExtender1.Hide();
}

http://forums.asp.net/t/1499789.aspx?confirmation+popup+from+server+side

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文