asp.net vb用户控件在调用页面上引发事件 [英] asp.net vb user control raising an event on the calling page

查看:191
本文介绍了asp.net vb用户控件在调用页面上引发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解用户控件。我创建了一个具有文本框和按钮的用户控件。我想要做的是当我单击用户控件中的按钮,在aspx页面中填充一个标签。我明白,我可以在页面上使用一个按钮,使用用户控件上的一些属性来获取该信息。但是我想知道如何使用用户控件的按钮。这样做的原因是该按钮只是一个例子..一个学习工具。如果我可以得到这个工作,我可能会把这些东西放在可能需要这种传递信息的用户控制中。无论如何..我发现一些C#示例,我试图得到工作作为vb ..但一旦开始进入代表和事件.. ..它让我转向这个职位。

i'm trying to learn about user controls. I created a user control that has a textbox and a button. What i'd like to be able to do is when i click the button in the user control, populate a label in the aspx page. I understand that i could just have a button on the page that uses some properties on the user control to get that information.. but i'd like to know how to do it with the button the user control.. the reason for this is the button is just an example.. a learning tool. if i can get this working, i'd likely be putting thing in the user control that might require this kind of passing information. Anyway.. i've found some c# examples that i tried to get working as vb.. but once started getting into the delegates and events.. well.. it made me turn to this post.

无论如何,希望有人可以借口。

anyway.. hopefully someone can lend a hand.

推荐答案

查看本教程可以帮助。这样做的最好方法绝对是打开一个事件,这不是你想象的那么难。基本信息是:

See if this tutorial can help. The best way to do this is definitely to wire up an event, which isn't nearly as hard as you think. The basics are:

1。在控制类中定义一个事件:

1. Define an event in your control class:

公共事件MyEvent as System.EventHandler

2。在控件类的子级或功能中提升事件:

2. Raise the event in a sub or function of your control class:

RaiseEvent MyEvent(Me,New EventArgs())

3。在包含您的控件的页面上处理事件:

3. Handle the event on the page that contains your control:

Protected Sub MyControl_MyEvent(ByVal sender As Object, ByVal e As EventArgs) Handles MyControl.MyEvent
    'Do stuff here
End Sub

这篇关于asp.net vb用户控件在调用页面上引发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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