委托并从父页面调用用户控制页面中的sub [英] delegate and call the sub in user control page from parent page

查看:56
本文介绍了委托并从父页面调用用户控制页面中的sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,它仅绑定一个gridview.我喜欢设置一个委托事件,并在各个页面上调用它.这是在asp.net vb中.
用户控制

i have a user control and it only binds a gridview. i like to set a delegate event and call it at various pages. this is in asp.net vb.
user control

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
             Call bindGV()
        End If

    End Sub

推荐答案

您不能调用事件",这不是方法.您可以调用事件,并且只能在声明事件的类中调用 ;即使在派生类中,也无法在其他任何地方调用它.与常规"委托实例相比,这是事件的重要限制之一,这是用于防止甚至滥用的一项重要的防呆功能.

使用该类的代码只能将处理程序添加到该类实例的可访问甚至实例的调用列表中.

您不清楚要做什么,但是您当然需要先了解事件和委托的工作方式.您要么需要使用其他东西(而不是事件),要么需要做其他事情.

您认为自己想做的事情在形式上是不可能的,但是可能您仍然需要做一些合理的事情.这就是为什么您还需要在问题中解释最终目标的原因,而又不了解如何从技术上实现目标,因为您可能会沉迷于一些错误的想法.

—SA
You cannot "call an event", it is not a method. You can invoke event, and only in the class where the event was declared; it is impossible to invoke it anywhere else, not even in a derived class. This is one of important limitations of the events compared with "regular" delegate instances, an important fool-proof feature used to prevent even misuse.

The code using the class can only add a handler to the invocation list of the accessible even instance of an instance of the class.

What are your trying to do is not clear, but you certainly need to understand how events and delegates work first. You either need to use something else, not an event, or you need to do something else.

What you think you want to do is formally impossible, but probably you still need to do something reasonable. That''s why you also need to explain your ultimate goals in your question, without using your understanding how to achieve it technically, as you could be preoccupied with some wrong idea.

—SA


这篇关于委托并从父页面调用用户控制页面中的sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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