zoukankan      html  css  js  c++  java
  • IPostBackEventHandler和IPostBackDataHandler有冲突?

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

    控件的源码如下:

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

    namespace TestMyRaise
    {
        
    /// <summary>
        
    /// RaiseTest 的摘要说明。
        
    /// </summary>

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


                
    set
                
    {
                    text 
    = value;
                }

            }

            
    public override bool EnableViewState
            
    {
                
    get{return base.EnableViewState;}
                
    set{base.EnableViewState=true;}
            }


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

                
    if(Click!=null)
                
    {
                    Click(
    this,e);
                }

            }


            
    protected override void Render(HtmlTextWriter writer)
            
    {
                writer.Write(
    "<input type=button value='clickme' id={0} onclick={1} />",UniqueID,Page.GetPostBackEventReference(this));
            }



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

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

    //            
    //        }

            
    IPostBackDataHandler 成员

            
    IPostBackEventHandler 成员
        }

    }


    调用的页面Test1.aspx如下:
    <%@ Register TagPrefix="Ra" Namespace="TestMyRaise" Assembly="TestMyRaise"%>
    <%@ Page language="c#" Codebehind="Test1.aspx.cs" AutoEventWireup="false" Inherits="Test5.RaiseTest.Test1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
        
    <HEAD>
            
    <title>Test1</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 MS_POSITIONING="GridLayout">
            
    <form id="Form1" method="post" runat="server">
                
    <Ra:RaiseTest runat="server" id="RaiseTest1" />
            
    </form>
        
    </body>
    </HTML>

    Test1.aspx.cs:
    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 Test5.RaiseTest
    {
        
    /// <summary>
        
    /// Test1 的摘要说明。
        
    /// </summary>

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


            
    Web 窗体设计器生成的代码

            
    private void RaiseTest1_Click(object sender, System.EventArgs e)
            
    {
                Response.Write(
    "Test");
            }

        }

    }

  • 相关阅读:
    USACO Milk2 区间合并
    Codeforces 490B Queue【模拟】
    HDU 3974 Assign the task 简单搜索
    HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
    Cin、Cout 加快效率方法
    POJ 1159 回文LCS滚动数组优化
    POJ 2479 不相交最大子段和
    POJ 1458 最长公共子序列 LCS
    在阿里最深刻的,还是职场之道给我的震撼
    精细化
  • 原文地址:https://www.cnblogs.com/Ermite/p/291580.html
Copyright © 2011-2022 走看看