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");
            }

        }

    }

  • 相关阅读:
    jquery 知识点
    java基础 知识点
    eclipse使用问题
    java中各种集合的用法和比较
    svn服务器安装
    dbcp连接mysql
    java中分页的实现
    在maven框架下遇到的问题及解决方法
    c++获取系统时间,精确到ms级
    qtcreator.exe已停止工作
  • 原文地址:https://www.cnblogs.com/Ermite/p/291580.html
Copyright © 2011-2022 走看看