完整的在.net舞台裏执行javascript脚本集
3165 ワード
/// <summary>
/// : , Page <form runat= server>
/// :page Page
/// script JavaScript , <script language=javascript>
/// : 。
/// </summary>
public static void RegisterStartupScript(System.Web.UI.Page page,string script)
{
string strKey;
int i;
// Key
strKey=System.DateTime.Now.ToString();
// , Key
for (i=0;i<100;i++)
if (!page.IsStartupScriptRegistered(strKey+i.ToString()))
break;
page.RegisterStartupScript(strKey+i.ToString(),script);
}
/// <summary>
/// : , Page <form runat= server>
/// :page Page
/// script JavaScript , <script language=javascript>
/// : 。
/// </summary>
public static void RegisterClientScriptBlock(System.Web.UI.Page page,string script)
{
string strKey;
int i;
// Key
strKey=System.DateTime.Now.ToString();
// , Key
for (i=0;i<100;i++)
if (!page.IsClientScriptBlockRegistered(strKey+i.ToString()))
break;
page.RegisterClientScriptBlock(strKey+i.ToString(),script);
}
#endregion
#region
/// <summary>
/// : , Page <form runat= server>
/// :page Page
/// script JavaScript
/// : 。
/// </summary>
public static void ExecuteBlock(System.Web.UI.Page page,string script)
{
string strScript;
string strKey;
int i;
//
strScript="<script language=javascript>
";
strScript+=" "+script+";";
strScript+="</script>";
// Key
strKey=System.DateTime.Now.ToString();
// , Key
for (i=0;i<100;i++)
if (!page.IsClientScriptBlockRegistered(strKey+i.ToString()))
break;
page.RegisterClientScriptBlock(strKey+i.ToString(),strScript);
}
/// <summary>
/// : , Page <form runat= server>
/// :page Page
/// script JavaScript
/// : 。
/// </summary>
public static void ExecuteStartup(System.Web.UI.Page page,string script)
{
string strScript;
string strKey;
int i;
//
strScript="<script language=javascript>
";
strScript+=" "+script+";";
strScript+="</script>";
// Key
strKey=System.DateTime.Now.ToString();
// , Key
for (i=0;i<100;i++)
if (!page.IsStartupScriptRegistered(strKey+i.ToString()))
break;
page.RegisterStartupScript(strKey+i.ToString(),strScript);
}