如何从asp.net中的代码调用确认消息? [英] How to call confirm message from code behind in asp.net?

查看:91
本文介绍了如何从asp.net中的代码调用确认消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想从asp.net中的代码调用客户端javascript确认消息。

Hi I want to call a client side javascript confirm message from code behind in asp.net.

我想使用确认消息中的true或false返回值。

I want to use the true or false return value from the confirm message.

我这样做,但这不是正确的方法,请告诉我如何才能这样做。

I'm doing like this, but this is not the correct way, please tell me how can I do the same.

ScriptManager.RegisterStartupScript(this, this.GetType(), "myconfirm", "confirm('No Rule Type Ids found for This Rule.');", true);


推荐答案

我认为这就是你想要实现的目标: / p>

I think This is what you want to achieve:

<script type = "text/javascript">
        function Confirm() {
            var confirm_value = document.createElement("INPUT");
            confirm_value.type = "hidden";
            confirm_value.name = "confirm_value";
            if (confirm("Do you want to save data?")) {
                confirm_value.value = "Yes";
            } else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }
    </script>

.aspx代码

<asp:Button ID="btnConfirm" runat="server" OnClick = "OnConfirm" Text = "Raise Confirm" OnClientClick = "Confirm()"/>

C#

public void OnConfirm(object sender, EventArgs e)
{
    string confirmValue = Request.Form["confirm_value"];
    if (confirmValue == "Yes")
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
    }
    else
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked NO!')", true);
    }
}

这篇关于如何从asp.net中的代码调用确认消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆