如何在C#Asp.net中注销Page.ClientScript [英] How to unregister Page.ClientScript in C# Asp.net

查看:105
本文介绍了如何在C#Asp.net中注销Page.ClientScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Java脚本注册到文件后面的Asp.net代码中,效果很好.现在,我在同一页面上有一些更新面板,问题是只要任何更新面板中的任何变化,该脚本都会自动被调用.有什么办法可以阻止这种情况的发生.我无法从页面上删除更新面板,并且此脚本也是应用程序中非常重要的一部分.在这种情况下,当我单击保存"按钮或调用更新"例程时,我只是调用一个警报(具有设置超时功能的警报),而我在更新面板中的其他按钮很少,并且无论何时注册了该更新的任何按钮单击面板,不情愿地调用以下脚本.任何人的帮助都将不胜感激.

I am registering java script to my Asp.net code behind file, which is working fine. Now, I have some update panels on the same page and problem is whenever there is any change in any of the update panel, this script is automatically getting called. Is there any way that I can stop this happening. I can't remove update panels from my page and this script is also a very essential part of the application. In this situation I am just calling a alert (rad alert with set time out functionality) when Save Button is clicked or an Update routine is called while I have few other buttons in update panels and whenver any of the button which is registered to the update panels clicked, the following script is called un-willingly. Anyone's help will really be appreciated.

以下是我的Page.ClientScript

following is my Page.ClientScript

                string radalertscript = "<script language='javascript'> Sys.Application.add_load(function(sender, e) {var oWnd = radalert('dialogMessage', 400, 140, 'Saved');window.setTimeout(function () { oWnd.Close(); }, 3000);});</script>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);

推荐答案

您可以将空字符串分配给同一键radalert以删除脚本.

You can assign empty string to same key radalert to remove the script.

if(some_condition)
    Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", "");

编辑:基于注释,您可以简化操作,而无需使用RegisterStartupScript

Based on comments, you can make it simple without using RegisterStartupScript

在后面的代码中

btnSave.Attributes.Add("", "saveButtonFunction();");

用Java语言

<script language='javascript'>

   Sys.Application.add_load(function(sender, e) {
           if(btnSaveClicked){
              var oWnd = radalert('dialogMessage', 400,140, 'Saved');
              window.setTimeout(function () { oWnd.Close(); }, 3000);
              btnSaveClicked = false;
           }
    });

    btnSaveClicked = false;
    function saveButtonFunction(){
       btnSaveClicked = true;
    };    

</script>

这篇关于如何在C#Asp.net中注销Page.ClientScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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