c#注册客户端事件示例

时间:2021-05-20

复制代码 代码如下:
/// <summary>
/// 注册客户端CSS文件
/// </summary>
/// <param name="page"></param>
/// <param name="relativeURL"></param>
public static void RegisterClientCSSFile(Page page, string relativeURL)
{
relativeURL = page.ResolveUrl(relativeURL);
page.Header.Controls.Add(new LiteralControl("\n<link href=\"" + relativeURL + "\" rel=\"stylesheet\" type=\"text/css\">\n"));
}
/// <summary>
/// 网页延迟退出
/// </summary>
/// <param name="page"></param>
/// <param name="script"></param>
/// <param name="delayTime">以秒为单位?</param>
public static void ClosePage(Page page, string script, int delayTime)
{
string closeScript. = "";
closeScript. += "<script. language=javascript>";
closeScript. += "setTimeout(\"ClosePage()\","+ (delayTime * 1000).ToString()+");";
closeScript. += "function ClosePage(){window.close();"+script+"};";
closeScript. += "</script>";

page.ClientScript.RegisterClientScriptBlock(page.GetType(), "ClosePage",
closeScript);
}
/// <summary>
/// 注册客户端脚本文件
/// Creator: Create Time:2009/7/22 13:47:20
/// </summary>
/// <param name="page"></param>
/// <param name="key"></param>
/// <param name="relativeURL"></param>
public static void RegisterClientScriptFile(Page page, string key, string relativeURL)
{
relativeURL = page.ResolveUrl(relativeURL);
if (!page.ClientScript.IsClientScriptIncludeRegistered(key))
{
page.ClientScript.RegisterClientScriptInclude(key, relativeURL);
}
}

/// <summary>
///
/// </summary>
/// <param name="control"></param>
public static void AutoBreakWord(WebControl control)
{
if (control != null)
{
control.Style.Add("word-break", "break-all");
}
}
/// <summary>
///
/// </summary>
/// <param name="control"></param>
public static void DisablePaste(WebControl control)
{
if (control != null)
{
control.Attributes.Add("onpaste", "event.returnValue=false;");
}
}
/// <summary>
///
/// </summary>
/// <param name="control"></param>
public static void DisableKeyDown(WebControl control)
{
if (control != null)
{
control.Attributes.Add("onkeydown", "event.returnValue=false;");
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章