c# - Removing scripts added by ClientScript.RegisterStartupScript - Stack Overflow

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

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

The JavaScript is:

function showDialog() {
    $(document).ready(function () {
        $(".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);
}

But no luck.

Is there any way to solve this problem?


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

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

The JavaScript is:

function showDialog() {
    $(document).ready(function () {
        $(".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);
}

But no luck.

Is there any way to solve this problem?


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

Share Improve this question asked Mar 25, 2012 at 14:23 Tapas BoseTapas Bose 29.9k78 gold badges220 silver badges338 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Try calling the function:

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

...in the Page_Load event handler.

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744566725a4581208.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信