zoukankan      html  css  js  c++  java
  • 为自定义控件添加页面响应事件

    ascx:
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    ascx.cs:
    (1)
    public delegate void PostBackDelegate();  //定义委托类型
    public event PostBackDelegate PostBackEvent;  //定义委托对象
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.PostBackEvent != null) this.PostBackEvent();  //无参数
    }
    (2)
    public event EventHandler PostBackHandler;
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.PostBackHandler != null) this.PostBackHandler(sender, e);  //有参数
    }
    aspx.cs:
    在Page_Load里(不是!IsPostBack里)加入:
    (1)
    MyUserControl1.PostBackEvent += new Test_MyFilePath_MyUserControl.PostBackDelegate(MyFuncName);  //new自动生成
    protected void MyFuncName()
    {
        Response.Write("OOKK");
    }
    (2)
    MyUserControl1.PostBackHandler += new EventHandler(MyFuncName);
    protected void MyFuncName(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        btn.Text = "控件按钮名称";  //改变控件按钮名称
        Response.Write("ookk");
    }
  • 相关阅读:
    django + scrapy 部署
    scrapyd 爬虫部署
    爬虫部署
    使用Scrapy爬取图片入库,并保存在本地
    学习Spider 了解 Scrapy的流程
    Django 的 一些基本操作:视图函数,路由配置
    Django 了解
    sql
    嚯嚯~ module 1
    Long Way To Go 之 Python 5 (2)
  • 原文地址:https://www.cnblogs.com/vipcjob/p/1534585.html
Copyright © 2011-2022 走看看