自定义复合控件[4]引发回递事件

using  System;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.ComponentModel;

namespace  csMathControl
{
    
/// <summary>
    
/// 引发回递事件
    
/// </summary>

    [DefaultProperty("Text"), 
        ToolboxData(
"<{0}:AlertButtonThree runat=server></{0}:AlertButtonThree>")]
    [DefaultEvent(
"Click")]
    
public class AlertButtonThree : System.Web.UI.WebControls.WebControl,IPostBackEventHandler
    
{
        
private string text;
    
        [Bindable(
true), 
            Category(
"Appearance"), 
            DefaultValue(
"")] 
        
public string Text 
        
{
            
get
            
{
                
return text;
            }


            
set
            
{
                text 
= value;
            }

        }

        
//-----------------------事件
        public event EventHandler Click;
        
/// <summary> 
        
/// 将此控件呈现给指定的输出参数。
        
/// </summary>
        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

        protected override void Render(HtmlTextWriter output)
        
{
            
//output.Write(Text);
            output.Write("<h3>Render控件,引发回嫡事件的</h3>");
            output.AddAttribute(
"value","用户自定义控件");
            output.AddAttribute(
"type","button");
            output.AddAttribute(
"onclick","javascript:alert('你好,小美女呵呵');"+Page.GetPostBackEventReference(this));//这个是关键
            output.RenderBeginTag("INPUT");
            output.RenderEndTag();
        }

        
        
IPostBackEventHandler 成员
        
protected virtual void OnClick(EventArgs e)
        
{
            
if(Click!=null)
                Click(
this,e);
        }

    }

}

你可能感兴趣的:(自定义)