动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 通过自定义类来达到向aspx页面加入脚本代码的例子

作者:loveolala(转) 来源:开发者俱乐部 
阅读 4362 人次 , 2002-1-4 

Set the InitialFocus for an ASP.NET WebForm
The PageUtil class has a static method SetInitialFocus(control) which can be used to generate a JavaScript for an ASP.NET page (WebForm), which sets the focus on a (given) control.

private void Page_Load(object sender, System.EventArgs e)
{
// Set the InitialFocus on TextBox1
PageUtil.SetInitialFocus(TextBox1);


using System;
using System.Web.UI;

namespace InitialFocusDemo
{
/// <summary>
/// Utility class for a ASP.NET page
/// </summary>
public class PageUtil
{

/// <summary>
/// Set the IntialFocus to the given control. Only works when JavaScript is supported.
/// </summary>
/// <param name="control">Control to set the InitialFocus on.</param>
public static void SetInitialFocus(Control control) {
if (control.Page == null) {
throw new ArgumentException("The Control must be added to a Page before you can set the IntialFocus to it.");
}
if (control.Page.Request.Browser.JavaScript == true) {
control.Page.RegisterClientScriptBlock("InitialFocus",
"<SCRIPT FOR='window' EVENT='onload' LANGUAGE='JScript'>document.all."
+ control.UniqueID + ".focus();</SCRIPT>");
}
}

}
}
  

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:.net中的事务处理(一)
· 下一篇:一个实现自动求和/合并单元格/排序的DataGrid
· 用asp.net写的论坛程序--浏览贴子内容及回复
· ASP.NET中利用存储过程实现模糊查询
· 10天学会ASP.net之第二天
· 在Servlet中使用请求头(Request Header) 
· JSP内幕


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077