Attributes.Add()

在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用。 即在后台页面加载时,调用JS方法。

语法格式有两种,

如下:

1.第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”);

如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm(‘确认?‘)”);

2.另一写法:控件ID名.Attributes["事件名称"]=“JS方法";

如:前台写了一个JS方法: function ISCheck(){。。。。。。}; Button1.Attributes[“onclick”]="ISCheck()";

编程实战:

this.txtBeginDate.Attributes["onclick"] = "return showCalendar(‘" + this.txtEmpName.ClientID + "‘,‘y/mm/dd‘)";
this.txtBeginDate.Attributes.Add("onclick", "return showCalendar(‘" + this.txtEmpName.ClientID + "‘,‘y/mm/dd‘)");

//以上两种方法是等效的

this.txtBeginDate.Attributes["readonly"] = "true";     //在txtBeginDate中添加readonly为True的属性。

this.txtBeginDate.Attributes.Add("readonly", "true");  //等效的写法

时间: 2024-08-10 02:11:02

Attributes.Add()的相关文章

当有“Button1.Attributes.Add("onclick", "return confirm('你确定要保存修改吗?')");”时,验证控件失效的解决方法

同一个页面用Js和服务器验证控件OnClientClick提交问题 实现功能:        点击Button按钮的OnClientClick事件,不会影响服务器验证控件的验证功能                                                (验证不通过,则不提交服务器页面)背景:       1. 在同一个页面有服务器验证控件(RegularExpressionValidator),多个       2. 有Javascript函数,实现验证和其他功能    

Attributes.Add用途与用法

Attributes.Add("javascript事件","javascript语句"); 如: this.TextBox1.Attributes.add("onblue", "window.Label1.style.backgroundColor='#000000';"); this.TextBox1.Attributes.Add("onblur","this.style.display='n

C#中的Attributes的用法

今天研究了一下C#中的Attributes的用法,感觉很有用,现总结以下: 在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用. 即在后台页面加载时,调用JS方法.语法格式有两种,如下: 第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”); 如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm('确认?')”); 另一写法:控件ID名.Attributes["事件名称"

Attributes

confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框. Attributes是指是属性的集合,位于using Systems.Web.UI.HtmlControls下,用于获取在ASP.NET页内的服务器空间标记上表示的所有属性名称和值对的集合. <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat=&quo

AttributeCollection.Add(String, String) Method

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void SubmitBtn_

Asp.net--GridView控件--(1)高亮显示当前所在行,(2)高亮显示单击行,(3)绑定数据库数据,(4)分页,(5)导出到excel表格,(6)首列插入序号

//本页代码中的DB类及方法在http://www.cnblogs.com/Deerjiadelu/p/7252769.html中能查询到 (1)Asp.net--GridView控件--高亮显示当前所在行 protected void gvquery_DataBound(object sender, GridViewRowEventArgs e) { //高亮显示光标所在行 if (e.Row.RowType == DataControlRowType.DataRow)//判断当前行是不是数据

Asp.net常用的51个代码(非常实用)

1.//弹出对话框.点击转向指定页面 Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script>"); Response.Write("<script>window.location ='http://www.51aspx.com/bizpulic/upmeb.aspx'</script>"); 2.//弹出对话框 Response.Write(&

框架页面尽可以这么用(后置代码中控制框架)

下面是框架页: <%@ Page CodeBehind="Frameset.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="IbatisTest.Web.Frameset" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"><HTML>

标签辅助类

自定义标签辅助类(Tag Helpers) 原文:Authoring Tag Helpers作者:Rick Anderson翻译:张海龙(jiechen)校对:许登洋(Seay) 示例代码查看与下载 从 Tag Helper 讲起 本篇教程是对 Tag Helper 编程作以介绍. Tag Helpers 介绍 描述了 Tag Helper 的优势. Tag Helper 是任何实现 ITagHelper 接口的类(Class).然而,当你编写一个 Tag Helper,你通常是从 TagHel