Re: User Control Event Handlers

Tech-Archive recommends: Fix windows errors by optimizing your registry



Gregory, this is what I came up with (in the ASCX page):

<script runat="server">
Public Event TextChanged(ByVal obj As Object)

Public Sub OnTextChanged(ByVal obj As Object, ByVal ea As
EventArgs) Handles txtAddress.TextChanged
RaiseEvent TextChanged(Me)
End Sub
</script>

Now how do I handle the event?

Please respond

rn5a@xxxxxxxxxxxxxx wrote:
Where should the event be bubbled up using RaiseEvent - in the ASCX
page?

Could you please link me to some articles on this topic?


Cowboy (Gregory A. Beamer) wrote:
If you need a control to fire an event on a parent: Bubble up the event to
the parent container using RaiseEvent.

1. Create an event

Public Event BubbleUpAlreadyRegistered As EventHandler(Of EventArgs)


2. Raise the event

RaiseEvent BubbleUpAlreadyRegistered(sender, e)


3. Handle the event

Protected Sub RegisterUnit1_BubbleUpUnitAlreadyRegistered(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
RegisterUnit1.BubbleUpAlreadyRegistered



If you need to do something on a control when the parent event is fired:
Fire the method on the control from code behind.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1160262681.709741.28640@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Consider the following user control which resides in Address.ascx:

<script runat="server">
Public Property Address() As String
Get
Address = txtAddress.Text
End Get
Set(ByVal value As String)
txtAddress.Text = value
End Set
End Property

Public Property Country() As String
Get
Country = txtCountry.Text
End Get
Set(ByVal value As String)
txtCountry.Text = value
End Set
End Property
</script>
<asp:TextBox ID="txtAddress" runat="server"/>
<asp:TextBox ID="txtCountry" runat="server"/>

This is how I am using the user control in a ASPX page:

<%@ Register TagPrefix="UC" TagName="UAddress" Src="Address.ascx" %>
<script runat="server">
Sub CopyAddress(obj As Object, ea As EventArgs)
..........
..........
End Sub
</script>
<form runat="server">
<UC:UAddress ID="ud" runat="server">
<asp:CheckBox ID="chkAddress" OnCheckedChanged="CopyAddress"
AutoPostBack="true" Text="Copy Address" runat="server"/>
</form>

The above ASPX page will render the 2 TextBoxes (using the user
control) & a CheckBox. Note that when the CheckBox is checked/unchecked
by the user, the sub named 'CopyAddress' gets executed.

Now I want the 2 TextBoxes to also execute the 'CopyAddress' sub using
the OnTextChanged event of the 2 TextBoxes but since the 2 TextBoxes
actually reside in the user control, how do I fire the OnTextChanged
event handler of the 2 TextBoxes so that the 'CopyAddress' sub gets
executed?


.



Relevant Pages

  • Re: Simple Insert Into...
    ... You can store unbound control data in a variable, ... in the sql. ... Dim strSQL As String ... In your form's Sub, you'll wind up with something like the following: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Addressing specific textboxes on a form
    ... A class module called "FormTboxClass" ... Private Sub FormTbox_Change ... Dim tmpctl As Control ... The textboxes are filled with numbers 1 to 26. ...
    (microsoft.public.excel.programming)
  • Re: User Control Event Handlers
    ... Where should the event be bubbled up using RaiseEvent - in the ASCX ... Protected Sub RegisterUnit1_BubbleUpUnitAlreadyRegistered(ByVal sender As ... Fire the method on the control from code behind. ... Now I want the 2 TextBoxes to also execute the 'CopyAddress' sub using ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Simple Insert Into...
    ... it is in a control on the form; and is unbound (it's actually a combo ... box that is used as a dropdown list, values taken from a different table; SQL ... I need this value to assign a unique ID to the entire recordset being ... In your form's Sub, you'll wind up with something like the following: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Deleting a textbox control at runtime
    ... because as soon as one of these becomes the zeroeth instance, ... Sub HideTextBoxes() ... Dim ctrl As Control ... > textboxes) giving a total of 20 textboxes. ...
    (microsoft.public.excel.programming)