用户控件HTML
<%
...
@ Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="WebApplication4.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"
%>
< asp:TextBox id ="TextBox1" runat ="server" ></ asp:TextBox >
< script language ="javascript" > ...
<!--
function <%= TextBox1.ClientID.Replace("_","")%>()
...{
document.all.<%= TextBox1.ClientID%>.value = "kent";
}
//-->
</ script >
< asp:TextBox id ="TextBox1" runat ="server" ></ asp:TextBox >
< script language ="javascript" > ...
<!--
function <%= TextBox1.ClientID.Replace("_","")%>()
...{
document.all.<%= TextBox1.ClientID%>.value = "kent";
}
//-->
</ script >
用户控件后台代码
namespace
WebApplication4
... {
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/**//// <summary>
/// WebUserControl1 的摘要说明。
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
...{
protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e)
...{
// 在此处放置用户代码以初始化页面
this.TextBox1.Attributes.Add("onmouseover",this.TextBox1.ClientID.Replace("_","")+"()");
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
... {
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/**//// <summary>
/// WebUserControl1 的摘要说明。
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
...{
protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e)
...{
// 在此处放置用户代码以初始化页面
this.TextBox1.Attributes.Add("onmouseover",this.TextBox1.ClientID.Replace("_","")+"()");
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}