您的位置:首页 > 编程语言

代码碎片(用户控件使用客户端脚本)

2007-09-23 11:57 211 查看
用户控件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>



用户控件后台代码


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


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: