Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net vb user control raising an event on the calling page

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.

like image 279
jvcoach23 Avatar asked Apr 07 '10 17:04

jvcoach23


People also ask

What is the extension for ASP NET user controls?

The file name extension for the user control is . ascx.


1 Answers

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. Define an event in your control class:

Public Event MyEvent as System.EventHandler

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

RaiseEvent MyEvent(Me, New EventArgs())

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
like image 118
tloflin Avatar answered Oct 09 '22 12:10

tloflin