gpt4 book ai didi

javascript - 如何在 asp.net c# 中执行下一行之前显示警报弹出窗口

转载 作者:行者123 更新时间:2023-11-30 16:18:42 25 4
gpt4 key购买 nike

我想在我的网络应用程序中显示警报/消息。我尝试了以下代码,但在执行所有代码行后显示警报。

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true); 

但是我想在代码执行行的中间显示我,是否可以,如果可能的话请帮助我..

最佳答案

正如我已经评论过的:

You cannot. RegisterStartupScript as you can read will register a startup script not call it. Also this script will be called only when response is received by client and processed. You can try a workaround for your scenario. Create a hidden button, and define a function to be processed after alert to this button. Then in your script, show alert and call click of this button.

您的函数可能如下所示:

public string myFunction(){
int a = 123;
.
.
.

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true);

.
.
.
.
.
return str;

}

你必须把这个函数分成两部分:

public string myFunction1(){
int a = 123;
.
.
.

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true);

return str;
}

public string myFunction2(){
.
.
.
.
.

}

并将myFunction1关联到原始事件,将myFunction2关联到隐藏按钮。然后将您的脚本更新为:

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message'); document.getElementById('<% hiddenBtn.clientId %>').click()", true); 

这将调用剩余的代码和流程逻辑。

注意 这是一个解决方法。理想情况下,您应该尝试拆分功能并尝试使用后台处理。

关于javascript - 如何在 asp.net c# 中执行下一行之前显示警报弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35083855/

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