使用C#进行事件冒泡 [英] Event Bubling with C#

查看:795
本文介绍了使用C#进行事件冒泡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们请帮帮我
我正在使用asp.net 3.5,并使用了一个Web项目
我有一个是UserControlEventArgs.cs的类,它是

hi friends please help me
i am using asp.net 3.5 and using i took a web project
i have a class which is UserControlEventArgs.cs which is

using System;

/// <summary>
/// Jeff Kent - 11/14/2009
/// EVENT CLASS THAT ENCAPSULATES THE EVENT ARGUMENTS.
/// </summary>
public class UserControlEventArgs : EventArgs
{

  //CONSTRUCTOR USED TO DETERMINE IF A
  //RECORD INSERTION WAS SUCCESSFUL.
  public UserControlEventArgs(bool InsertComplete)
  {
    if (InsertComplete)
    {
      this.InsertComplete = true;
    }
    else
    {
      this.InsertComplete = false;
    }
  }

  private bool _InsertComplete;
  public bool InsertComplete{
    get { return _InsertComplete ; }
    set { _InsertComplete = value; }
  }

}

//DECLARE THE EVENT DELEGATE FOR THE CONTROL.
//NOTE HOW THE DELEGATE RESIDES OUTSIDE THE SCOPE OF THE CLASS.
public delegate void ClubInsertedEventHandler(object sender, UserControlEventArgs e);



一个Web用户控件是WebUserControlAddUser.ascx



And one web user control is WebUserControlAddUser.ascx

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

/// <summary>
/// Jeff Kent - 11/14/2009
/// SAMPLE WEB USER CONTROL WITH EVENT BUBBLING SUPPORT.
/// THE FORM VIEW CONTROL IS USED TO COLLECT AND PROCESS CLUB INFORMATION.
/// ONLY THE INSERT ITEM TEMPLATE IS USED IN THIS EXAMPLE.
/// </summary>
public partial class WebUserControlAddUser : System.Web.UI.UserControl
{

  //DECLARE THE DELEGATE VARIABLE.
  public event ClubInsertedEventHandler ClubInsertComplete;

  //PUT THE FORM VIEW INTO THE INSERT MODE 
  //EVERY TIME THE PAGE LOADS THE CONTROL.
  protected void FormView1_Load(object sender, EventArgs e)
  {
    FormView1.ChangeMode(FormViewMode.Insert);
  }

  // THE FORM VIEW CONTROL CAN BE TRICKY. 
  // THE WORK AROUND THE QUIRKS IS TO INTERCEPT THE ITEMCOMMAND EVENT
  // THEN USE THE SWITCH STRUCTURE TO CONTROL THE STATE OF THE CONTROL.
  protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
  {
      UserControlEventArgs args;
      switch (e.CommandName)
      {
        case "StartInsert":
          //NOT USED IN THIS IMPLEMENTATION.
          break;
        case "CommitInsert":
          InsertNewClub();
          FormView1.ChangeMode(FormViewMode.ReadOnly);

          //FIRE THE EVENT TO SEND NOTICE TO
          //THAT THE CLUB SUBBMISSION WAS SUCCESSFUL.
          args = new UserControlEventArgs(true);
          ClubInsertComplete(this, args);

          break;
        case "CancelInsert":
          FormView1.ChangeMode(FormViewMode.ReadOnly);
          FormView1.DataBind();

          //FIRE THE EVENT TO SEND NOTICE TO
          //THAT THE CLUB SUBBMISSION WAS CANCELLED.
          args = new UserControlEventArgs(false);
          ClubInsertComplete(this, args);

          break;
        default:
          break;
    }
  }

  //OBTAIN THE DATA FROM THE FORM 
  //AND INSERT IT INTO THE DATA TABLE.
  protected void InsertNewClub()
  {
    TextBox tb;

    tb = (TextBox)FormView1.FindControl("ClubID");
    int ClubID = Convert.ToInt32(tb.Text);
    tb = (TextBox)FormView1.FindControl("ClubName");
    string ClubName = tb.Text;
    tb = (TextBox)FormView1.FindControl("URL");
    string url = tb.Text;

    ClubList.AddClub(ClubID, ClubName, url);
  }
}





我对程序集引用感到困惑.您缺少using指令或程序集引用"
为什么在我运行程序时出现错误

我已将该行设置为粗体,请检查





i am confused about assembly reference ."you are missing a using directive or an assembly reference"
why the error comes when i run the program

i have made that line bold please check

推荐答案

该错误表示您正在尝试在程序中使用未定义的类或方法,因为(因为它明确指出)您缺少using指令或程序集引用" .检查您要访问的类的文档并修复引用.
The error means that you are trying to use a class or method in your program that is not defined, because (as it clearly states) "you are missing a using directive or an assembly reference". Check the documentation for the class you are trying to access and fix the reference.


我几次遇到此错误.每次获得它意味着我都在.NET X Client Profile 中进行构建.确保您没有选择客户端配置文件",而是常规的.NET版本.您可以在编译"选项卡下的项目选项"中找到它.
除此之外,错误是不言自明的.希望对您有所帮助.
I got this error a couple of times. Every time I got it it meant I was building in .NET X Client Profile. Make sure you don''t select Client Profile, but the regular .NET version. You can find it in your Project Options under the Compile tab.
Other than that the error is pretty self-explanatory. Hope it helps.


这篇关于使用C#进行事件冒泡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆