IPostBackEventHandler和IPostBackDataHandler有冲突?

去掉IPostBackDataHandler后,RaisePostBackEvent就执行了,为什么?

控件的源码如下:

None.gif using  System;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.ComponentModel;
None.gif
None.gif
namespace  TestMyRaise
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// RaiseTest 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [DefaultProperty("Text"), 
InBlock.gif        ToolboxData(
"<{0}:RaiseTest runat=server></{0}:RaiseTest>")]
InBlock.gif    
public class RaiseTest : System.Web.UI.WebControls.WebControl,INamingContainer,IPostBackEventHandler,IPostBackDataHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private string text;
InBlock.gif        
InBlock.gif        
public event EventHandler Click;
InBlock.gif        
InBlock.gif        [Bindable(
true), 
InBlock.gif            Category(
"Appearance"), 
InBlock.gif            DefaultValue(
"")] 
InBlock.gif        
public string Text 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return text;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                text 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
public override bool EnableViewState
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return base.EnableViewState;}
ExpandedSubBlockStart.gifContractedSubBlock.gif            
setdot.gif{base.EnableViewState=true;}
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected virtual void OnClick(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif
//            EventHandler handler1=(EventHandler)base.Events[RaiseTest.EventClick];
InBlock.gif
//            if(handler1!=null)
InBlock.gif
//            {
InBlock.gif
//                handler1(this,new EventArgs());
InBlock.gif
//            }
InBlock.gif

InBlock.gif            
if(Click!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Click(
this,e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            writer.Write(
"<input type=button value='clickme' id={0} οnclick={1} />",UniqueID,Page.GetPostBackEventReference(this));
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 将此控件呈现给指定的输出参数。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

InBlock.gif        
InBlock.gif
//        protected override void RenderContents(HtmlTextWriter writer)
InBlock.gif
//        {
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**/////            writer.WriteBeginTag("input");
InBlock.gif
////            writer.WriteAttribute("type","submit");
InBlock.gif
////            writer.WriteAttribute("id",UniqueID);
InBlock.gif
////            writer.WriteAttribute("name",UniqueID);
InBlock.gif
////            writer.Write(" />");
ExpandedSubBlockEnd.gif
////            writer.Write(Text);

InBlock.gif//            
InBlock.gif
//        }
InBlock.gif

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IPostBackDataHandler 成员#region IPostBackDataHandler 成员
InBlock.gif
InBlock.gif        
public virtual void RaisePostDataChangedEvent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// TODO:  添加 RaiseTest.RaisePostDataChangedEvent 实现
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        
public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            text
=postCollection[UniqueID];
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IPostBackEventHandler 成员#region IPostBackEventHandler 成员
InBlock.gif
InBlock.gif        
public void RaisePostBackEvent(string eventArgument)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Page.Response.Write(
"asdfasdfasd");
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

调用的页面Test1.aspx如下:
ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Register TagPrefix="Ra" Namespace="TestMyRaise" Assembly="TestMyRaise" %>
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif @ Page language="c#" Codebehind="Test1.aspx.cs" AutoEventWireup="false" Inherits="Test5.RaiseTest.Test1"  %>
None.gif
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > Test1 </ title >
None.gif        
< meta  name ="GENERATOR"  Content ="Microsoft Visual Studio .NET 7.1" >
None.gif        
< meta  name ="CODE_LANGUAGE"  Content ="C#" >
None.gif        
< meta  name ="vs_defaultClientScript"  content ="JavaScript" >
None.gif        
< meta  name ="vs_targetSchema"  content ="http://schemas.microsoft.com/intellisense/ie5" >
None.gif    
</ HEAD >
None.gif    
< body  MS_POSITIONING ="GridLayout" >
None.gif        
< form  id ="Form1"  method ="post"  runat ="server" >
None.gif            
< Ra:RaiseTest  runat ="server"  id ="RaiseTest1"   />
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif

Test1.aspx.cs:
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
namespace  Test5.RaiseTest
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Test1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Test1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected TestMyRaise.RaiseTest RaiseTest1;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.RaiseTest1.Click += new System.EventHandler(this.RaiseTest1_Click);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void RaiseTest1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"Test");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/Ermite/archive/2005/12/06/291580.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值