gpt4 book ai didi

c# - 删除由 ClientScript.RegisterStartupScript 添加的脚本

转载 作者:行者123 更新时间:2023-11-30 13:22:14 31 4
gpt4 key购买 nike

在我的应用程序的登录控件中,如果登录失败,我将显示一个对话框窗口。这样:

protected void EMSLogin_Authenticate(object sender, AuthenticateEventArgs e) {
log.Info("=============INSIDE EMSLogin_Authenticate======");
RadTextBox UserName = EMSLogin.FindControl("UserName") as RadTextBox;
RadTextBox Password = EMSLogin.FindControl("Password") as RadTextBox;

if (Membership.ValidateUser(UserName.Text, Password.Text)) {
FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
} else {
ClientScript.RegisterStartupScript(typeof(ScriptManager), "CallShowDialog", "showDialog();", true);
}
}

JavaScript 是:

function showDialog() {
$(document).ready(function () {
$(".jym").dialog("open");
});
}

现在,如果登录失败,将显示该对话框。但问题是,如果我刷新浏览器窗口,在一次登录失败后,对话框再次打开,因为 $(".jym").dialog("open") 写在页面中。那我试过了

protected void Page_Unload(object sender, EventArgs e) {        
log.Info("=============INSIDE Page_Unload======");
ClientScript.RegisterStartupScript(typeof(ScriptManager), "CallShowDialog", "", true);
}

但没有运气。

有什么办法可以解决这个问题吗?


如果我使用 ClientScript.RegisterClientScriptBlock() 这不起作用,我的意思是对话框没有打开错误。

最佳答案

尝试调用函数:

ClientScript.RegisterStartupScript(typeof(ScriptManager), "CallShowDialog", "", true);

...在 Page_Load 事件处理程序中。

Page_Load 发生在按钮单击事件处理程序之前。您可以通过添加以下代码并查看调试/输出窗口来验证这一点:

protected void Page_Load(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Page_Load");
}

protected void Button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Button1_Click");
}

因此,在 Page_Load 事件处理程序中删除脚本应该会清除所有先前加载的脚本。

关于c# - 删除由 ClientScript.RegisterStartupScript 添加的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9860905/

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