gpt4 book ai didi

c# - 在 if..else.. 条件下的 Javascript 确认

转载 作者:太空宇宙 更新时间:2023-11-03 20:09:50 25 4
gpt4 key购买 nike

我必须在特定条件下显示确认对话框。然后根据单击"is"或“否”继续。我尝试了以下操作。

在 aspx 中:

<script type="text/javascript">
function ShowConfirmation() {
if (confirm("Employee Introduced already.Continue?") == true) {
document.getElementById("hdn_empname").value = 1;
}
}

</script>

<asp:HiddenField ID="hdn_empname" runat="server" />

在计算机科学中:

  if (reader2.HasRows)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "showAl", "ShowConfirmation();", true);
}
else
{
hdn_empname.Value ="1";
}

if ((hdn_empname.Value)=="1")
{
//some code to execute
}

但是 hdn_empname 在调试时显示 value=""

谁能帮我做这件事?

提前致谢。

最佳答案

试一试 您需要 ClientID

document.getElementById('<%=hdn_empname.ClientID%>').value = 1;

我发现了你的主要问题

The hidden field values will assign after the if condition call.

编辑:

因此,您需要使用 ajax 在 javascript 端调用您的逻辑

if (confirm("Employee Introduced already.Continue?") == true) {

//some code to execute
}

关于c# - 在 if..else.. 条件下的 Javascript 确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20728371/

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