实施落后C#在code JavaScript的确认框 [英] Implementing javascript confirm box in code behind C#

查看:112
本文介绍了实施落后C#在code JavaScript的确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现从code后面的javascript确认框。

I want to implement javascript confirm box from code behind.

我的要求是一个方法,我需要提出一个确认框,根据结果我需要实现差异functionalites

My requirement is in a method I need to raise a confirm box ,based on the result I need to implement diff functionalites

例如;

如果确认框确定的加税

如果取消然后不加税

我想这样的事情,但它不是帮助我

I am trying something like this but its not helping me

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Add tax');", true);

谁能帮助。

我的样本code是

protected void Button1_Click(object sender, EventArgs e)
{
    Double mrp = 200.00;

    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "return confirm('Add Tax');", true);
    if (Confirm == "Ok")
    {
        //Add tax to mrp
    }
    else
    {
        //No tax for mrp
    }
}

感谢您..

推荐答案

你可以尝试这样的:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <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>
</head>
<body>
    <form id="form1" runat="server">
      <asp:Button ID="btnConfirm" runat="server"
                  OnClientClick = "Confirm()"
                  OnClick="OnConfirm" 
                  Text="Raise Confirm"/>
    </form>
</body>
</html>

抓取用户的输入服务器端

现在服务器端,我们需要获取我们存放在动态隐藏字段,然后根据他是否选择确定或取消,我们需要执行不同的code中的用户输入。

Fetching the User input server side

Now server side we need to fetch the user input that we stored in the dynamic hidden field and then based on whether he has selected OK or Cancel we need to execute different code.

public void OnConfirm(object sender, EventArgs e)
{
    string confirmValue = Request.Form["confirm_value"];
    if (confirmValue == "Yes")
    {
        //Your logic for OK button
    }
    else
    {
        //Your logic for cancel button
    }
}

从<一个href=\"http://aspsnippets.com/Articles/Server-Side-$c$c-Behind-Yes-No-Confirmation-Message-Box-in-ASPNet.aspx\"相对=nofollow>服务器端(code后面)是否在ASP.Net确认消息框

From Server Side (Code Behind) Yes No Confirmation Message Box in ASP.Net

这篇关于实施落后C#在code JavaScript的确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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