作者:overred 来源:原创
自描绘控件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace myc
{
/// <summary>
/// myrcontrol 的摘要说明。
/// </summary>
public class myrcontrol: Control,IPostBackEventHandler,IPostBackDataHandler
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("<INPUT type=text name=\"{0}\">",this.UniqueID);
writer.Write("<INPUT type=button value=\"adv\" onclick=\"adv('hello world')\">",this.UniqueID);
writer.Write("<INPUT type=button value=\"Click Me!\" onclick=\"{0}\">",Page.GetPostBackEventReference(this));
}
#region IPostBackEventHandler 成员
public void RaisePostBackEvent(string eventArgument)
{
//if(!Page.IsPostBack)
Page.Response.Write("RaisePostBackEvent(string eventArgument)");//捕获按钮事件
}
#endregion
#region IPostBackDataHandler 成员
public void RaisePostDataChangedEvent()
{
// TODO: 添加 myrcontrol.RaisePostDataChangedEvent 实现
}
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
// TODO: 添加 myrcontrol.LoadPostData 实现
Page.Response.Write(postCollection[this.UniqueID]);//捕获提交数据
//postCollection[this.UniqueID];
return false;
}
#endregion
protected override void OnPreRender(EventArgs e)
{
Page.RegisterClientScriptBlock("advv","<SCRIPT language=\"JScript\" src=\"adv.js\"></SCRIPT>");//注册js
base.OnPreRender (e);
}
}
}
在其他的aspx页应用
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="myc.WebForm1" %>
<%@ Register TagPrefix="myuc" NameSpace="myc" Assembly="myc" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<myuc:myrcontrol runat="server" id="Myrcontrol1"></myuc:myrcontrol>
</form>
</body>
</HTML>
posted @ 2005-10-11 10:43
overred 阅读(151)
评论(1) 编辑 收藏