是否可以将一个事件称为另一个事件 [英] Is it possible to Call one Event into Another Evevnt

查看:74
本文介绍了是否可以将一个事件称为另一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个事件称为另一个事件......我们可以完成这个任务......



I want to call One Event into Another Event... can we do this task...

protected void DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e)
    {
        DetailsView1.ChangeMode(e.NewMode);
        DetailsView1.DataSource = GetDetails.GetEmpDetailsById(Convert.ToInt32(Session["empId"]));
        DetailsView1.DataBind();
    }



    protected void btnEdit_Click(object sender, EventArgs e)
    {

    }





我只想将DetailsView1_ModeChanging活动调成btnEdit_Click,如下所示







Just I want to Call a "DetailsView1_ModeChanging" Event into a "btnEdit_Click" Just Like below


protected void btnEdit_Click(object sender, EventArgs e)
    {
       DetailsView1_ModeChanging(object sender, DetailsViewModeEventArgs e);
    }





如果有可能,我们可以通过发件人和e



如果我的问题有任何问题请原谅我但我想知道答案.... Plz帮帮我



谢谢

Bajid Khan



If it is possible Above One how can pass sender and e

If any thing wrong in my Question Please forgive me But i want know the answer.... Plz help me

Thanks
Bajid Khan

推荐答案

.NET中没有调用事件这样的概念。事件instanced被调用,这是一个非常不同的事情,但这只在声明类型中允许,在其他地方,甚至在派生类中都不允许。这是一个很好的理由,作为一个万无一失的功能。



你不是呼叫事件,你正在调用一些可以用作某个事件实例的处理程序,如果它通过+ =运算符添加到这些事件实例的调用列表中。 (实际上,调用偶数实例会逐个调用所有处理程序。)此方法调用与任何其他方法调用没有什么不同,所以你可以这样做。



传递sender和event参数的问题很难实现。这只是一个电话,没有别的。如果您的处理程序方法(如 DetailsView1_ModeChanging )不使用,例如 sender ,则勇敢地传递null。如果使用了一个或两个参数,则应传递有意义的参数,并由处理程序正确处理。例如,使用其构造函数在调用点创建 DetailsViewModeEventArgs 的实例。我不知道你的目的,所以这取决于你。只有方法和方法体的调用才能达成一定的协议。再次,与任何常规方法调用一样。



-SA
There is no such concept in .NET as "calling an event". Event instanced are invoked, which is a very different thing, but this is allowed only in the declaring type, nowhere else, not even in derived classes. This is set for a good reason, as a fool-proof feature.

You are not "calling event", you are calling some method which could be used as a handler for some event instance, if it is added to an invocation list of these event instance via the += operator. (Actually, invocation of an even instance causes calls of all handlers one by one.) This method call is no different from any other method calls, so you can do it.

Your problem with passing the sender and event argument parameter is poorly artificial. This is just a call, nothing else. If your handler method like DetailsView1_ModeChanging does not use, say, sender, bravely pass null. If one or both parameters are used, you should pass the parameter which makes sense and will be correctly processed by the handler. For example, create an instance of DetailsViewModeEventArgs at the point of call using its constructor. I don't know your purpose, so it's up to you. Only the call of the method and method body should be in certain agreement. Again, as always with any regular method call.

—SA


这篇关于是否可以将一个事件称为另一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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