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

查看:192
本文介绍了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.

推荐答案

看看<一个href=\"http://$c$cbetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx\">this教程可以提供帮助。要做到这一点,最好的办法肯定是要连接的事件,这是不是几乎很难,因为你的想法。基本要点有:

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为System.EventHandler

2。在控制类的子或函数引发事件:

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

的RaiseEvent MyEvent(ME,新的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天全站免登陆