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

脚本|页面

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>");
            }
        }

    }
}
 

时间: 2024-08-04 01:43:59

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

怎样将dll反编译出来的代码放入对应的.aspx页面的后台代码,使之成为未编译之前的那样

问题描述 怎样将dll反编译出来的代码放入对应的.aspx页面的后台代码,使之成为未编译之前的那样,即一个.aspx页面有对应的.cs文件,应该怎么做 解决方案 解决方案二:雇佣一个程序员,而不是总想着偷窃人家的代码.解决方案三:反编译之后,看懂它,然后自己手打一遍..虽然是别人的,至少也锻炼了一下自己..

SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决

不能编辑自定义类 你选中一个Sub File(CCBFile)节点,在这个例子中,该节点的Custom class区域灰化禁用且不能修改.这是因为你需要在该Sub File引用的CCB文件中修改Custom class. 不能给节点添加通用属性 为了使一个节点拥有自定义属性,必须给其赋予一个自定义类(这个不一定,也可以用其通用父类作为自定义类).该自定义类需要的属性或实例变量与通用属性的名字相匹配.

javascript 异步页面查询实现代码(asp.net)_javascript技巧

1. testlist.aspx页面: 复制代码 代码如下: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link rel="stylesheet" href="jscript/autoSuggest.css" type="text/css&q

使用自定义的PageHandler处理aspx页面获取页面的执行时间

使用自定义的PageHandler处理所有的aspx页面获取页面的执行时间 using System; using System.Web; using System.Web.UI; using System.Web.SessionState; namespace Cuyahoga.Web.HttpHandlers { /// <summary> /// This class handles all aspx page requests for Cuyahoga. /// </summar

ASP.NET的中自定义类实现统一身份验证程序代码

在ASP.NET开发过程中,经常会进行身份验证.比较麻烦的做法是,对每个页面添加验证代码.我们知道,ASP.NET的页面都继承自System.Web.UI.Page类,我们可以自定义一个类,让它继承自Page类,并在该类中添加验证操作.然后让需要验证的页面类,继承自我们定义的这个类,就可以实现统一验证功能. 1.创建用于验证页面的基类BasePage,该类继承自Page类  代码如下 复制代码 using System; using System.Data; using System.Linq;

aspx 页面生命周期

客户端请求页面 1.预初始化(OnPreInit) 2.初始化(OnInit) 3.完成初始化(OnInitComplete) 4.载入ViewState(LoadViewState) 5.处理回送数据(IPostBackDataHandler) 6.Page_OnPreLoad->Page_OnLoad 7.回发更改通知(RaisePostDataChangedEvent) 8.处理回发事件(RaisePostBackEvent) 9.Page_OnLoadComplete 10.预呈现(On

Ajax.Net的onLoading及aspx页面的默认名字空间及ajaxpro的google组怎么没有一个chinese?

ajax|google|loading|名字空间|页面 这是ajax.net作者做的onLoading demo.下载他的代码来看,有几点疑问:1,如果一个aspx页面没有后置代码cs类文件,或者在vs2005中没有给他手动加上名字空间,那么aspx的默认的名字空间是什么呢?难道是ASP??我想大家可能都没有注意到这个问题吧.请教吴旗娃师傅,他立即Response.Write(this.GetType().ToString())告诉我了结果,千真万确是ASP:2,如果一个类中包含了Ajax.Ne

分享:aspx页面&amp;#106avascript的几个trick

页面 1.一般而言,如果想给aspx页面上的web form control加上一些javascript的特性,可以用Attributes.Add来实现. 例如,对TextBox txt,可以:txt.Attributes.Add("onclick", "fcn0();"); 那么,在web页面上click它的时候,就会调用fcn0这个javascript函数. 1.1.例外的情况是,对于IDE无法辨认的属性的解析. 比如对一个RadioButton rbt,IDE

Asp.net Web控件自定义类属性(经验篇)

asp.net|web|控件 做控件设计时,我们往往需要用自己定义的类来做为控件的属性, 但是,很不幸的是,IDE并不能预先知道新类别的诞生,因此,我们需要 有TypeConverter来做个转换,把自己定义的对象转换为字符串显示到控件 的属性页中,把属性页中的字符串(颜色在aspx中的体现也是字符串,如: #eef008)转换为自定义类.           TypeConverter实现步骤可以有以下两种方式:           一:套用系统定义的TypeConverter类,对自定义属性