ASP.NET操作JavaScript的类

本文介绍了一个抽象类ScriptDAL,该类提供了在ASP.NET Web应用程序中执行客户端JavaScript脚本的方法,包括直接输出自定义脚本和注册客户端启动脚本。

using System;
using System.Text;

namespace Eyu.Common
{
    
/**////


    
/// 消息提示
    
///
    public abstract class ScriptDAL
    
{        
        
/**////
        
/// 显示一段自定义的输出代码
        
///
        
/// 页面指针,一般为This
        public static void ResponseScript(System.Web.UI.Page page, string script)
        
{
             StringBuilder sb
= new StringBuilder();
             sb.Append(
"");
             page.Response.Write(sb.ToString());
         }


        
/**////
        
/// 调用客户端JavaScript函数
        
///
        
/// 页面指针,一般为This
        
/// 函数名,带参数,如:FunA(1);
        public static void CallClientScript(System.Web.UI.Page page,string scriptName)
        
{
             String csname
= "PopupScript";
             Type cstype
= page.GetType();
             System.Web.UI.ClientScriptManager cs
= page.ClientScript;
            
if (!cs.IsStartupScriptRegistered(cstype, csname))
            
{
                 String cstext
= scriptName;
                 cs.RegisterStartupScript(cstype, csname, cstext,
true);
             }

         }


      

    



     }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值