gpt4 book ai didi

c# - 如何从 asp.net 中的代码后面调用确认消息?

转载 作者:太空狗 更新时间:2023-10-30 01:36:12 24 4
gpt4 key购买 nike

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

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

我正在这样做,但这不是正确的方法,请告诉我如何做同样的事情。

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

最佳答案

我想这就是你想要实现的:

<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);
}
}

关于c# - 如何从 asp.net 中的代码后面调用确认消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22910796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com