手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

UpdatePanel和自定义控件中的客户端脚本

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

( HttpContext.Current.Items["__ClientScriptProxy"] ??

(HttpContext.Current.Items["__ClientScriptProxy"] =

new ClientScriptProxy(HttpContext.Current.Handler as Page)))

as ClientScriptProxy;

}

}

/// <summary>

/// Base constructor. Pass in the page name so we can pick up

/// the stock the

/// </summary>

/// <param name="CurrentPage"></param>

protected ClientScriptProxy(Page CurrentPage)

{

this.clientScript = CurrentPage.ClientScript;

}

/// <summary>

/// Checks to see if MS Ajax is registered with the current

/// Web application.

///

/// Note: Method is static so it can be directly accessed from

/// anywhere

/// </summary>

/// <returns></returns>

public static bool CheckForMsAjax()

{

scriptManagerType = Type.GetType("Microsoft.Web.UI.ScriptManager, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);

if (scriptManagerType != null)

{

_IsMsAjax = true;

return true;

}

_IsMsAjax = false;

return false;

}

/// <summary>

/// Registers a client script block in the page.

/// </summary>

/// <param name="control"></param>

/// <param name="type"></param>

/// <param name="key"></param>

/// <param name="script"></param>

/// <param name="addScriptTags"></param>

public void RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags)

{

if (this.IsMsAjax)

{

if (RegisterClientScriptBlockMethod == null)

RegisterClientScriptBlockMethod = scriptManagerType.GetMethod("RegisterClientScriptBlock");

RegisterClientScriptBlockMethod.Invoke(null, new object[5] { control, type, key, script, addScriptTags });

}

else

this.clientScript.RegisterClientScriptBlock(type, key, script, addScriptTags);

}

/// <summary>

/// Registers a startup code snippet that gets placed at the bottom of the page

/// </summary>

/// <param name="control"></param>

/// <param name="type"></param>

/// <param name="key"></param>

/// <param name="script"></param>

/// <param name="addStartupTags"></param>

public void RegisterStartupScript(Control control, Type type, string key, string script, bool addStartupTags)

{

if (this.IsMsAjax)

{

if (RegisterStartupScriptMethod == null)

RegisterStartupScriptMethod = scriptManagerType.GetMethod("RegisterStartupScript");

RegisterStartupScriptMethod.Invoke(null, new object[5] { control, type, key, script, addStartupTags });

}

else

this.clientScript.RegisterStartupScript(type, key, script, addStartupTags);

}

/// <summary>

/// Registers a script include tag into the page for an external script url

/// </summary>

/// <param name="control"></param>

/// <param name="type"></param>

/// <param name="key"></param>

/// <param name="url"></param>

public void RegisterClientScriptInclude(Control control, Type type, string key, string url)

{

if (this.IsMsAjax)

{

if (RegisterClientScriptIncludeMethod == null)

RegisterClientScriptIncludeMethod = scriptManagerType.GetMethod("RegisterClientScriptInclude");

RegisterClientScriptIncludeMethod.Invoke(null, new object[4] { control, type, key, url });

}

else

this.clientScript.RegisterClientScriptInclude( type, key, url);

}

/// <summary>

/// Adds a script include tag into the page for WebResource.

/// </summary>

/// <param name="control"></param>

/// <param name="type"></param>

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!