删除由ClientScript.RegisterStartupScript添加的脚本 [英] Removing scripts added by ClientScript.RegisterStartupScript

查看:65
本文介绍了删除由ClientScript.RegisterStartupScript添加的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序的登录控件中,如果登录失败,我将显示一个对话框窗口.通过这种方式:

In my application's login control, I am showing a dialog window if the login failed. In this way:

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是:

The JavaScript is:

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

现在,如果登录失败,则显示对话框.但是问题是如果刷新浏览器窗口,一次登录失败后,由于在页面中写入了 $(.jym").dialog("open"),对话框再次打开.然后我尝试了

Now if the login failed the dialog is showing. But The problem is if I refresh the browser window, after one login failed, the dialog again opened, since the $(".jym").dialog("open") is written in the page. Then I have tried

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

但是没有运气.

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

Is there any way to solve this problem?

如果我使用 ClientScript.RegisterClientScriptBlock()无效,则表示对话框未在错误时打开.

If I use ClientScript.RegisterClientScriptBlock() this not working, I mean the dialog is not opening on error.

推荐答案

尝试调用该函数:

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

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

...in the Page_Load event handler.

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

Page_Load occurs before the button click event handler. You can verify this by adding the following code and looking in the debug/output window:

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事件处理程序中的脚本应清除以前加载的所有脚本.

So erasing the script in the Page_Load event handler should clear any previous script that was loaded.

这篇关于删除由ClientScript.RegisterStartupScript添加的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆