我想从后面的代码实现javascript确认框.
我的要求是根据我需要实现diff功能的结果,我需要提出一个确认框
例如;
如果OK确认框添加税
如果取消则不加税
我正在尝试这样的事情,但它没有帮助我
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Add tax');", true);
Run Code Online (Sandbox Code Playgroud)
谁能帮忙.
我的示例代码是
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
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢..
你能尝试这样吗:
<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>
Run Code Online (Sandbox Code Playgroud)
现在服务器端我们需要获取我们存储在动态隐藏字段中的用户输入,然后根据他是选择了OK还是取消,我们需要执行不同的代码.
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39750 次 |
| 最近记录: |